Skip to content

Instantly share code, notes, and snippets.

@daveworth
Created December 12, 2011 23:03
Show Gist options
  • Select an option

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

Select an option

Save daveworth/1469559 to your computer and use it in GitHub Desktop.
Data separated from Model!
class OurModel < ActiveRecord::Base
# ... snip ...
#
def generate_csv_template(account_id)
csv_headers = OurModel.human_attribute_name("csv_template_headers")
headers = CustomModel.find_all_by_account_id(account_id).map(&:name)
CSV.generate do |csv|
csv << [*csv_headers.split(/\s*,\s*/), *headers]
end
end
end
en:
activerecord:
attributes:
our_model:
csv_template_headers: first_name,last_name,birth_date,pet_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment