Episodes
David Kimura PRO said almost 6 years ago on Importing and Exporting CSV Data :

Have a look at this branch compare. (https://github.com/driftingrub...

You basically will need to temporarily create a file to store it and pass the path to ActiveJob. While this is currently working on local filestore, it can also work with S3 or fog.


David Kimura PRO said almost 6 years ago on Importing and Exporting CSV Data :

The * is a splat operator. So, take the following example.

[2] pry(main)> fields
=> ["first_name", "last_name"]
[3] pry(main)> User.first.attributes.values_at(fields)
User Load (0.5ms)SELECT`users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1
=> [nil]
[4] pry(main)> User.first.attributes.values_at(*fields)
User Load (0.5ms)SELECT`users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1
=> ["System", "Administrator"]

http://blog.honeybadger.io/rub...

The ! at the end of find_or_create_by will raise an exception on validation errors.


osazemeu said over 5 years ago on Importing and Exporting CSV Data :

How do I export nested attributes to CSV? i.e. I have a primary contact model, and I nested secondary contact into it. How do I export both as single CSV file?


wade0727 said almost 3 years ago on Importing and Exporting CSV Data :
What's the best approach to this using the Kaminari Gem so that I can pull all rows in the index, not just the amount listed on the first page? ``` def index search = params[:term].present? ? params[:term] : nil @nodes = if search Node.search(search) else Node.order(:node).page(params[:page]) end respond_to do |format| format.html format.csv { send_data @nodes.to_csv, filename: "nodes-#{Date.today}.csv" } end end ```

David Kimura PRO said almost 3 years ago on Importing and Exporting CSV Data :
You can do a check if the `request.format.csv?` is true and exclude the `page(params[:page])` method.

wade0727 said almost 3 years ago on Importing and Exporting CSV Data :
Wow, that was easier than I thought it was going to be. Thank you!! :)

Login to Comment