Ruby on rails Rails 3.0.4中没有路由匹配
这个问题已经研究了一段时间了。这是我尝试查看页面时遇到的错误Ruby on rails Rails 3.0.4中没有路由匹配,ruby-on-rails,routes,Ruby On Rails,Routes,这个问题已经研究了一段时间了。这是我尝试查看页面时遇到的错误 No route matches {:action=>"confirm", :controller=>"locations"} 这就是我的看法 <%= form_for(@location, :url => { :action => :confirm }) do |f| %> <% end %> 有什么想法吗 更新: 运行rake路线,得到我认为正确的结果 confirm_locat
No route matches {:action=>"confirm", :controller=>"locations"}
这就是我的看法
<%= form_for(@location, :url => { :action => :confirm }) do |f| %>
<% end %>
有什么想法吗
更新:
运行rake路线,得到我认为正确的结果
confirm_location POST /locations/:id/confirm(.:format) {:action=>"confirm", :controller=>"locations"}
您是否在LocationsController中定义了确认操作?通过运行
$rake routes
并查看输出,您可以在将来轻松调试路由。;)
我认为发生的情况是,您的post:confirm
没有注册您期望的路线。在指南中,match
并接受字符串作为URL段,如下所示:
resources :locations do
member do
post 'confirm'
end
end
请注意,“确认”现在是字符串而不是符号
如果这没有帮助,请运行$rake routes
,并将输出添加到您的问题上
更新
在看到rake输出后,我认为您只需要在表单_上为
指定POST方法:
<%= form_for(@location, :url => { :action => :confirm }, :method => :post) do |f| %>
<% end %>
{:action=>:confirm},:method=>:post)do | f |%>
您还可以使用Rails定义的帮助器方法使其更具可读性:
<%= form_for(@location, :url => confirm_location_path(@location), :method => :post) do |f| %>
<% end %>
confirm|location|u path(@location),:method=>:post)do | f |%>
尝试添加一个:method=>:post
到您的表单中
<%= form_for(@location, :url => { :action => :confirm }, :method => :post) do |f| %>
<% end %>
{:action=>:confirm},:method=>:post)do | f |%>
如果您已在路由文件中将路由声明为仅接受post,请确保表单\u for不会以\u method=put潜入隐藏字段。猜得不错,但这不是问题所在;他在查看表单时出错,因为的隐式url\u无法找到为他指定的参数定义的路由。谢谢,@coreyward。重写你的建议似乎暴露了问题@location
还没有id,所以这条路线不起作用是有道理的。@Garrett:这是有道理的。很高兴我们弄明白了。您可以将方法
参数删除到的表单中。资源丰富的路由对象不需要它,但如果使用自定义url
参数,您可能会发现它是必需的。一旦你有了工作,一点拨弄应该会明确地告诉你这两种情况。
<%= form_for(@location, :url => { :action => :confirm }, :method => :post) do |f| %>
<% end %>