KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Currently, if I want to apply a method to a group of ActiveRecord objects, I have to structure the call like so: messages = Message.find(:all) csv = Message.to_csv(messages) How can I define the method so it's structured like so? messages = Message.find(:all) csv = messages.to_csv This is the current model code: require 'fastercsv' class Message < ActiveRecord::Base def Message.to_csv(messages) FasterCSV.generate do |csv| csv << ["from","to", "received"] for m in messages csv << [m.from,m.to,m.created_at] end end end end
Tags (comma-separated)
Save Edits
Cancel