CrudVision - Lisa Seelye

June 30, 2007

wants.csv?

Filed under: evedb.info, rails, snippet — Lisa Seelye @ 10:40

So you're looking to spit back CSV? Here's some Agent stuff for the RESTification of evedb.info! the

RUBY:
  1. @agents.collect{ |a| a}.each do |agent|

is for paginating_find to return all the Agents.

RUBY:
  1. format.csv do
  2.         cols = Agent.columns.map(&:name).sort
  3.         csv_str = FasterCSV.generate do |csv|
  4.           csv.push cols
  5.           @agents.collect{ |a| a}.each do |agent|
  6.             row = []
  7.             cols.each do |k|
  8.               row.push agent.attributes[k]
  9.             end
  10.             csv.push row
  11.           end
  12.         end
  13.         render :text => csv_str

Powered by WordPress