我需要在 Rails appl 中将数据导出为 CSV。我找到了这个插件:https://github.com/crafterm/comma https://github.com/crafterm/comma。您知道更好的解决方案吗?
如果使用 Ruby 1.9.x,则使用 CSV 而不是 FasterCSV,并坚持使用默认分隔符。
控制器:
respond_to do |format|
...
format.csv { render :layout => false }
end
显示.csv.erb:
<%= this_is_your_view_helper_method.html_safe %>
控制器_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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)