在rails中将数据导出为CSV

我需要在rails appl中将导出数据作为CSV。 我找到了这个插件: 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 

查看此Stack Overflow应用程序,以便在Ruby 1.9.x中使用CSV(正如Fletch所说,它包含FasterCSV,但语法略有不同)。