导出数据 CSV 在 rails

我需要将数据导出为 CSV 在 rails appl. 我找到了这个插件:
https://github.com/crafterm/comma
. 也许你知道任何更好的解决方案吗?
已邀请:

快网

赞同来自:

如果您正在使用 Ruby 1.9.x, 然后使用 CSV, 但不是 FasterCSV 并坚持默认的分隔符。

控制器:


respond_to do |format|
...
format.csv { render :layout => false }
end


show.csv.erb:


<%= this_is_your_view_helper_method.html_safe %>


controller_helper.rb:


require 'csv'

def this_is_your_view_helper_method
CSV.generate do |csv|
Product.find/:all/.each do |product|
csv << ... add stuff here ...
end
end
end

帅驴

赞同来自:

检查这一点
https://coderoad.ru/4822422/
Stack Overflow 用来 CSV 在 Ruby 1.9.x /作为手动指出,其中包括 FasterCSV, 但是有一些其他语法/.

要回复问题请先登录注册