Exporting CSV data from Rails -


i'm working export csv data rails. i'm following tutorial here: http://railscasts.com/episodes/362-exporting-csv-and-excel?view=asciicast

in controller have:

  def show     # @company being provided correctly.     @groups = @company.groups     render text: @groups.to_csv   end   

in group.rb model:

  def self.to_csv     rails.logger.info "hello world"     csv.generate |csv|       csv << column_names       all.each |product|         csv << product.attributes.values_at(*column_names)       end     end   end 

the issue browser outputting following:

#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,#,# 

the model method appears being ignored, after rails restart. ideas what's wrong here? thanks

the to_csv class method. meaning meant called group.to_csv. might want change method signature group.to_csv(groups) instead.

 def self.to_csv(groups)     rails.logger.info "hello world"     csv.generate |csv|       csv << column_names       groups.each |product|         csv << product.attributes.values_at(*column_names)       end     end   end 

then in show

  def show     # @company being provided correctly.     @groups = @company.groups     render text: group.to_csv(@groups)   end   

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -