Skip to content

Instantly share code, notes, and snippets.

@daveworth
Created December 20, 2011 13:18
Show Gist options
  • Select an option

  • Save daveworth/1501536 to your computer and use it in GitHub Desktop.

Select an option

Save daveworth/1501536 to your computer and use it in GitHub Desktop.
A good first pass.
class OurModel < ActiveRecord::Base
# ... snip ...
def generate_csv_template(account_id)
headers = <<HEADERS
first_name,last_name,pet_name
HEADERS
headers += CustomModel.find_all_by_account_id(account_id).
map(&:name).join(",")
CSV.generate { |csv| csv << headers.split(/\s*,\s*/)}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment