Running Rails 3.2.11,我有一个常规控制器“LbuController”,它基本上是一个增强的脚手架,增加了4个额外的GET方法用于AJAX请求。资源 - 路由与嵌套GET中断资源路由?
resources :lbus do
get 'add_offering'
get 'remove_offering'
get 'add_offering_element'
get 'remove_offering_element'
end
运行rake routes
给了我下面的路线
lbu_add_offering GET /lbus/:lbu_id/add_offering(.:format) lbus#add_offering
lbu_remove_offering GET /lbus/:lbu_id/remove_offering(.:format) lbus#remove_offering
lbu_add_offering_element GET /lbus/:lbu_id/add_offering_element(.:format) lbus#add_offering_element
lbu_remove_offering_element GET /lbus/:lbu_id/remove_offering_element(.:format) lbus#remove_offering_element
lbus GET /lbus(.:format) lbus#index
POST /lbus(.:format) lbus#create
new_lbu GET /lbus/new(.:format) lbus#new
edit_lbu GET /lbus/:id/edit(.:format) lbus#edit
lbu GET /lbus/:id(.:format) lbus#show
PUT /lbus/:id(.:format) lbus#update
DELETE /lbus/:id(.:format) lbus#destroy
这似乎正好是我故意的。
但下面的链接与link_to "new", new_lbu_path
创建http://localhost:3000/lbus/new
给了我以下错误:
No route matches {:action=>"add_offering", :lbu_id=>nil, :offering_id=>1, :controller=>"lbus"}
这使得完全没有意义的我。 有人有什么想法这里发生了什么,出了什么问题?
在此先感谢!
我不认为这个错误与新行为有关。但它指的是add_offering - >在新的控制器动作中还是在点击“新”后重定向到的视图中有错误? – cruxi
@Oliver在'新'视图中,您必须使用lbu_add_offering路径。这条路似乎是不正确的。错误指的是:action =>“add_offering” – Nishant
不,它必须是路由相关的问题。只要我用'get'方法删除块,'new'操作就可以按预期工作。 – Oliver