I have the following button to download a file.
= button_to \'download\', action: \'download\', method: \'get\'
And I have a download
Try this, it should work with your view code just change into routes.rb
resources :movies do
get :download, :on => :collection
end
In your routes.rb:
resources :movies do
get 'download', on: :member
end
Now, in your view you need to specify, what movie you want to download:
= button_to 'download', download_movie_path(@movie), method: 'get'
Also, note:
Use path instead of specifying controller/action in helpers.
Use link_to for GET requests and if you need link with button style apply it through CSS. button_to with GET request is a bad practice.
Alternatively, if you want to specify controller/action (which has advantages, since it allows you to pass through arbitrary params), you'll need to also explicitly pass along any parameters that action relies on (assuming you're trying to download an individual movie, and not the entire collection).
button_to 'download', {controller: 'movies', action: 'download', id: movie.id }, method: 'get'
Also, ditto Mikhail D's point about using link_to for "get" requests. Defining the method explicitly is great for sending requests to the "update" action (by setting method: :patch or method: :puts), but for "gets" just use link_to.