Ruby-on-rails Rails 路由的未初始化常量问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1126587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uninitialized constant problem for Rails routes
提问by Laran Evans
Here's my route configuration:
这是我的路由配置:
map.resources :services do |services|
services.resources :capabilities do |capabilities|
capabilities.resources :http_headers
end
end
Here's my "rake routes" output:
这是我的“耙路线”输出:
laran:trunk laran$ rake routes
(in /Users/laran/workspace/kibo/mega/server/trunk)
accounts GET /accounts(.:format) {:action=>"index", :controller=>"accounts"}
POST /accounts(.:format) {:action=>"create", :controller=>"accounts"}
new_account GET /accounts/new(.:format) {:action=>"new", :controller=>"accounts"}
edit_account GET /accounts/:id/edit(.:format) {:action=>"edit", :controller=>"accounts"}
account GET /accounts/:id(.:format) {:action=>"show", :controller=>"accounts"}
PUT /accounts/:id(.:format) {:action=>"update", :controller=>"accounts"}
DELETE /accounts/:id(.:format) {:action=>"destroy", :controller=>"accounts"}
services GET /services(.:format) {:action=>"index", :controller=>"services"}
POST /services(.:format) {:action=>"create", :controller=>"services"}
new_service GET /services/new(.:format) {:action=>"new", :controller=>"services"}
edit_service GET /services/:id/edit(.:format) {:action=>"edit", :controller=>"services"}
service GET /services/:id(.:format) {:action=>"show", :controller=>"services"}
PUT /services/:id(.:format) {:action=>"update", :controller=>"services"}
DELETE /services/:id(.:format) {:action=>"destroy", :controller=>"services"}
service_capabilities GET /services/:service_id/capabilities(.:format) {:action=>"index", :controller=>"capabilities"}
POST /services/:service_id/capabilities(.:format) {:action=>"create", :controller=>"capabilities"}
new_service_capability GET /services/:service_id/capabilities/new(.:format) {:action=>"new", :controller=>"capabilities"}
edit_service_capability GET /services/:service_id/capabilities/:id/edit(.:format) {:action=>"edit", :controller=>"capabilities"}
service_capability GET /services/:service_id/capabilities/:id(.:format) {:action=>"show", :controller=>"capabilities"}
PUT /services/:service_id/capabilities/:id(.:format) {:action=>"update", :controller=>"capabilities"}
DELETE /services/:service_id/capabilities/:id(.:format) {:action=>"destroy", :controller=>"capabilities"}
service_capability_http_headers GET /services/:service_id/capabilities/:capability_id/http_headers(.:format) {:action=>"index", :controller=>"http_headers"}
POST /services/:service_id/capabilities/:capability_id/http_headers(.:format) {:action=>"create", :controller=>"http_headers"}
new_service_capability_http_header GET /services/:service_id/capabilities/:capability_id/http_headers/new(.:format) {:action=>"new", :controller=>"http_headers"}
edit_service_capability_http_header GET /services/:service_id/capabilities/:capability_id/http_headers/:id/edit(.:format) {:action=>"edit", :controller=>"http_headers"}
service_capability_http_header GET /services/:service_id/capabilities/:capability_id/http_headers/:id(.:format) {:action=>"show", :controller=>"http_headers"}
PUT /services/:service_id/capabilities/:capability_id/http_headers/:id(.:format) {:action=>"update", :controller=>"http_headers"}
DELETE /services/:service_id/capabilities/:capability_id/http_headers/:id(.:format) {:action=>"destroy", :controller=>"http_headers"}
/login {:action=>"login", :controller=>"accounts"}
/logout {:action=>"logout", :controller=>"accounts"}
root / {:action=>"index", :controller=>"default"}
laran:trunk laran$
When I go to /services/new though, I get this error:
但是,当我转到 /services/new 时,出现此错误:
NameError in ServicesController#new uninitialized constant ServicesController::Services
What gives? How can I get things working and routed correctly? Thanks.
是什么赋予了?我怎样才能让事情正常工作并正确路由?谢谢。
采纳答案by Ben Hughes
Is ServicesController backed up by a model Service? Did you accidentally reference it as Services in your controller?
ServicesController 是否由模型服务支持?您是否不小心在控制器中将其引用为服务?
回答by Jim Puls
This probably doesn't have anything to do with your routes; your newmethod in ServicesController is trying to use a (class? constant? object?) named Servicesthat doesn't exist.
这可能与您的路线无关;您new在 ServicesController 中的方法试图使用一个(类?常量?对象?)命名的Services不存在。

