没有路由匹配 [POST] "/users/new"; [英] No route matches [POST] "/users/new"
本文介绍了没有路由匹配 [POST] "/users/new";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮我解决这个错误.
错误:没有路由匹配 [POST] "/users/new"
我的代码片段是:
views/users/index.html.erb
<h1>这是注册页面..</h1><div class="sign"><%= button_to "注册",{:controller =>"用户", :action =>"new",method: :get} %><%= button_to "Login",action:"login" , method: :get %>
config/route.rb
Rails.application.routes.draw 做根用户#index"获取用户/新用户"=>用户#新"获取用户/登录"=>用户#登录"#get "users/new" =>用户#new",如:new_user#get "users/login" =>"users#login", as: login_user结尾
请帮我设置路由文件.
解决方案
首先通过命名您的路线让您的生活更轻松:
# in config/routes.rbRails.application.routes.draw 做根用户#index"获取用户/新用户"=>"users#new", :as =>:新用户获取用户/登录"=>"users#login", :as =>:登录结尾
进一步注意 :method
参数是第三个(不是第二个)参数的一部分:
<%= button_to "注册", new_user_path, :method =>:get%><%= button_to "登录", login_path, :method =>:get%>
或者没有命名路由:
<%= button_to "注册", { :controller =>"用户", :action =>"new" }, :method =>:get%><%= button_to "登录", { :action =>登录"},方法=>:get%>
注意大括号.
Please help me for resolve this error.
Error: No route matches [POST] "/users/new"
My code snippets are:
views/users/index.html.erb
<h1>This is Registration page..</h1>
<div class="sign">
<%= button_to "Registration",{:controller => "users", :action => "new",method: :get} %>
<%= button_to "Login",action:"login" , method: :get %>
</div>
config/route.rb
Rails.application.routes.draw do
root "users#index"
get "users/new" => "users#new"
get "users/login" => "users#login"
#get "users/new" => "users#new", as: new_user
#get "users/login" => "users#login", as: login_user
end
Please help me to setup the routes file.
解决方案
First make your life easier by naming your routes:
# in config/routes.rb
Rails.application.routes.draw do
root "users#index"
get "users/new" => "users#new", :as => :new_user
get "users/login" => "users#login", :as => :login
end
Furthermore notice that the :method
argument is part of the third (not second) argument:
<%= button_to "Registration", new_user_path, :method => :get %>
<%= button_to "Login", login_path, :method => :get %>
Or without the named routes:
<%= button_to "Registration", { :controller => "users", :action => "new" }, :method => :get %>
<%= button_to "Login", { :action => "login" }, method => :get %>
Note the curly brackets.
这篇关于没有路由匹配 [POST] "/users/new";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文