No route matches [POST] “/sessions/new” (rails 4 in action)

前端 未结 1 1186
长情又很酷
长情又很酷 2021-01-25 13:50

I\'m following the Rails 4 In action book and I\'m running into the following error:

No route matches [POST] \"/sessions/new\" 

I\'m not sure w

1条回答
  •  野性不改
    2021-01-25 14:32

    You are correct there is an error in this book.

    When you have a form for tag

    <%= form_for :signin, method: "POST" do |f| %>
    

    If rails doesn't know what :signin means, then it will simply copy the current url and will submit the form to that url (in this case 'sessions/new'), using the post verb (whether you specify it or not!)

    ....

    Obviously, that's not necessarily what you want because you don't have a /sessions/new for post HTTP verb, I think the easiest solution would be to specify a route

    post "/signin", to: "sessions#create", as: "signin"
    

    and in your form_for

    <%= form_for signin_path do |f| %>
    

    0 讨论(0)
提交回复
热议问题