“No route matches [POST]” when changing link_to to button_to

前端 未结 4 671
余生分开走
余生分开走 2021-02-04 04:45

I have this piece of code:

<%= link_to \"New User\", new_user_path, :class => \"button\"  %>

which works fine, but when I

4条回答
  •  北海茫月
    2021-02-04 04:50

    button_to defaults to POST, and link_to defaults to GET, this is why links_to worked. You can force button_to to use GET:

    <%= button_to "New User", new_user_path, :class => "button", :method => :get %>
    

    You can get more information about button_to options here: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to

提交回复
热议问题