Perhaps an oddball question. Doing a Model.all or the like gets me a somewhat pretty output of the array, [#<Model id:5, name:"Blahblah">,#<Model id:5, name:"Etc">]. Is there an easy way to convert this into a CSV/Excel format with the attributes as columns?
Perhaps an oddball question. Doing a Model.all or the like gets me a somewhat
Share
Yes.
Use the FasterCSV gem to generate a CSV from a list of your models.
But there’s no good way to do this automatically. So you should add a class method to your model that produces the CSV from an array.
example:
Warning: it’s not going to be perfect, you’re still going to get a string that starts and ends with
". But it’s pretty easy to remove the start and end quotes.