Search code examples
ruby-on-railsexport-to-csv

Export to csv with respond_to returns errors on rails 5


With Rails version 5.2.rc1

if I use

respond_to do |format|
  format.csv { render(csv: "test") }
end

results

ActionController::UnknownFormat

What is the best way to export to csv in rails 5?


Solution

  • Please look into the Railscast's screencast. If you followed everything properly and still you're getting the error, then try something like this in your routes:

    match '/yourPathTo.csv' => 'controller#action', via: :get, defaults: { format: :csv }