Routing Error - No route matches when using button_to with custom action

后端 未结 3 2024
礼貌的吻别
礼貌的吻别 2021-01-23 11:34

I have the following button to download a file.

= button_to \'download\', action: \'download\', method: \'get\'

And I have a download

3条回答
  •  北海茫月
    2021-01-23 11:46

    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:

    1. Use path instead of specifying controller/action in helpers.

    2. 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.

提交回复
热议问题