我已经盯着这个问题看了一段时间。当我尝试查看页面时,出现了以下错误。
No route matches {:action=>"confirm", :controller=>"locations"}
这是我在视图中拥有的内容。
<%= form_for(@location, :url => { :action => :confirm }) do |f| %>
<% end %>
我认为我的路由文件设置正确。
Finder::Application.routes.draw do
resources :locations do
member do
post :confirm
end
end
root :to => 'locations/index'
end
有什么想法吗?
更新:
运行rake routes,我认为得到了正确的结果。
confirm_location POST /locations/:id/confirm(.:format) {:action=>"confirm", :controller=>"locations"}
@location
还没有一个id,所以这个路由不能起作用是有道理的。 - Garrett Murpheyform_for
中删除method
参数。对于资源路由对象,它是不需要的,但如果你使用自定义的url
参数,你可能会发现它是必需的。一旦你让事情正常工作,稍微探索一下就能确定是否需要。 - coreyward