Skip to content

Instantly share code, notes, and snippets.

@radar
Created November 23, 2008 08:28
Show Gist options
  • Save radar/28067 to your computer and use it in GitHub Desktop.
Save radar/28067 to your computer and use it in GitHub Desktop.
require 'fastercsv'
class ActiveRecord::Base
def self.to_csv(objects, skip_attributes=[])
FasterCSV.generate do |csv|
csv << attribute_names - skip_attributes
objects.each do |object|
csv << (attribute_names - skip_attributes).map { |a| "'#{object.attributes[a]}'" }.join(", ")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment