Why did he use :put
and how should I route it ?
The form:
<p>Sign Up</p>
<%= form_for @user, :as => :user, :url => new_user_path, :method => :put do |f| %>
...
<% end %>
There is a :put
at the end and as you can see he didn't show how to route the :put
-method.
My route.rb looks like this:
Calendar::Application.routes.draw do
root "welcome#index"
get "user/change_pw"
get "user/forgot_pw"
get "user/new" => "user#new"
get "user/sent_pw"
get "user/sign_in" => "user#sign_in"
get "user/signed_out" => "user#signed_out"
get "welcome/index"
post "user/sign_in" => "user#login"
post "user/new" => "user#register"
end
If I click "Sign up" the following error appears:
No route matches [PUT] "/user/new"
Any ideas ?
By "convention" the form code is incorrect. For a new resource, you should be using post
method and not put
method. Please see Representational state transfer for details on the different http methods.
As shown, you also already have post "user/new" => "user#register"
route defined, so fix the view code by either removing the :method => :put
as form_for
defaults to post
, or by replacing the method to :post
.
<%= form_for @user, :as => :user, :url => new_user_path do |f| %>