我的路由看起来像这样:
Improvement::Application.routes.draw do
#Protocols
resources :protocols
#Improvements
root :to => 'pimps#index', :as => 'pimps'
get '/new(.:format)', :to => 'pimps#new', :as => 'new_pimp'
get '/:id/edit(.:format)', :to => 'pimps#edit', :as => 'edit_pimp'
get '/:id/(.:format)', :to => 'pimps#show', :as => 'pimp'
post '/(.:format)', :to => 'pimps#create'
put '/:id(.:format)', :to => 'pimps#update'
patch '/:id(.:format)', :to => 'pimps#update'
delete '/:id(.:format)', :to => 'pimps#destroy'
#One Pager (nested in Improvements)
get '/:pimp_id/onepager/new(.:format)', :to => 'mepagers#new', :as => 'new_mepager'
get '/:pimp_id/onepager/edit(.:format)', :to => 'mepagers#edit', :as => 'edit_mepager'
get '/:pimp_id/onepager(.:format)', :to => 'mepagers#show', :as => 'mepager'
post '/:pimp_id/onepager(.:format)', :to => 'mepagers#create', :as => 'create_mepager'
put '/:pimp_id/onepager(.:format)', :to => 'mepagers#update'
patch '/:pimp_id/onepager(.:format)', :to => 'mepagers#update'
delete '/:pimp_id/onepager(.:format)', :to => 'mepagers#destroy'
#Business Case (nested in Improvements)
get '/:pimp_id/bcase/new(.:format)', :to => 'bcases#new', :as => 'new_bcase'
get '/:pimp_id/bcase/edit(.:format)', :to => 'bcases#edit', :as => 'edit_bcase'
get '/:pimp_id/bcase(.:format)', :to => 'bcases#show', :as => 'bcase'
post '/:pimp_id/bcase(.:format)', :to => 'bcases#create', :as => 'create_bcase'
put '/:pimp_id/bcase(.:format)', :to => 'bcases#update'
patch '/:pimp_id/bcase(.:format)', :to => 'bcases#update'
delete '/:pimp_id/bcase(.:format)', :to => 'bcases#destroy'
#Organisation Units
resources :org_units
end
现在如果我打电话给http://localhost:3000/protocols
一切正常,我就进入协议页面。但是,如果我调用http://localhost:3000/org_units
rails尝试以某种方式使用pimps_controller并搜索pimp
- 具有id ='org_units'的对象。如果我像这样指定路线和控制器
get '/org_units(.:format)', :to => 'org_units#new', :as => 'org_units'
发生同样的错误。
我试图找出protocols
和org_unit
之间我的代码是否存在差异,但我无法找到。
所以也许你知道我的错误所在。
最好的问候。
答案 0 :(得分:0)
好的,明白了。显然,重要的是我写了我的routes.rb!将resources :org_units
放在首位就行了!