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

前端 未结 4 674
余生分开走
余生分开走 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 05:12

    The "link_to" is looking for a /users/new using GET.

    The "button_to" is looking for a /users/new using POST

    If you create the routes for a controller using:

    resources :user
    

    By default, /users/new is a GET and not POST so, the second line doesn't find any route.

    If you are thinking to change that action to POST I think that you should forget about it.

提交回复
热议问题