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

后端 未结 3 2036
礼貌的吻别
礼貌的吻别 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:58

    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.

提交回复
热议问题