I’m using comma gem to download my contacts into csv format. However there’s a requirement in which I’m required to rename the attribute name from first_name to First Name and I’m wondering how do I do that.
My comma DSL in my contact model is as follows
comma do
id
first_name
last_name
email
phone
end
so for first_name and last_name I’m looking for some option that would allow me to convert
first_name => "First Name" and last_name => "Last Name" something like that, any suggestions?
By the way, I’m using Rails 3.1 and Ruby 1.9.2
Update:
In my controller, I have a select query that uses some joins as well, for instance:
UserJob.joins(:rounds, :works).select("user_job.first_name AS firstname, user_job.last_name AS lastname … ")
So comma looks for first_name in the object’s attributes but since it’s been modified in the query as firstname it generates a missing attribute error so I’m wondering how do I tell comma that first_name is actually firstname.
If you want to have the headers “First Name” and “Last Name” in the CSV, you can specify the header directly: