If I do:
Contact.select('email').first(1000).to_json
I get a JSON response with emails... How can I get just a CSV of emails? [email protected], [email protected]
I'm trying to do this from rails console.
Thanks
If I do:
Contact.select('email').first(1000).to_json
I get a JSON response with emails... How can I get just a CSV of emails? [email protected], [email protected]
I'm trying to do this from rails console.
Thanks
You can install this plugin to have the to_csv method. Or you can implement it yourself.
I would vote for the prior, because if you'll need to print out names instead of emails you should implement the escaping as well, and this would be there for you by the plugin.
Update:
Oh I have not realized that you need only the mails, with this plugin you could do the following:
@emails = Contact.select('email').first(1000).map(&:email)
respond_to do |format|
format.html
format.xml { render :xml => @emails }
format.csv { send_data @emails.to_csv }
end