我想命名我的控制器
ESCsController
,
ESC
是所讨论的首字母缩略词。我找到了rails拐点文档,这些文档描述了实现这一点的方法。
http://api.rubyonrails.org/classes/ActiveSupport/Inflector/Inflections.html
注意:传递给复数形式的首字母缩略词将不再被识别,因为在复数形式的结果中,首字母缩略字不会作为分隔单位出现。要解决此问题,还必须将复数形式指定为首字母缩略词:
acronym 'API'
camelize(pluralize('api'))
acronym 'APIs'
camelize(pluralize('api'))
将此添加到后,我创建了控制器和模型
environment.rb
ActiveSupport::Inflector.inflections { |i|
i.acronym 'ESC'
i.acronym 'ESCs'
}
在控制台中测试,这些功能完美。
'ESC'.pluralize()
回报
ESCs
和
'ESCs'.singularize()
回报
电子计算机
正如预期的那样
控制器和模型通过
rails generate model ESC
和
rails generate controller ESCs
分别地这已创建
escs_controller.rb
和模型
esc.rb
正如预期的那样。
在我的路线中
resources :ESCs, path: '/parts/escs'
返回此错误:
'ESCs' is not a supported controller name. This can lead to potential routing problems. See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use
我最终将其更改为:
resources :ESCs, controller: 'escs', path: '/parts/escs'
然而,现在每当我尝试访问一个页面时,我都会收到一个循环依赖性错误:
Circular dependency detected while autoloading constant EscsController
有人知道怎么回事吗?看起来任何试图加载控制器的东西都没有看到它应该是
ESC控制器
而不是
EscsController
。我是新手,所以这可能是个简单的问题。。。
我使用的是Rails 4.0.2
这是完整堆栈跟踪的相关部分。
activesupport (4.0.2) lib/active_support/dependencies.rb:461:in `load_missing_constant'
activesupport (4.0.2) lib/active_support/dependencies.rb:184:in `const_missing'
activesupport (4.0.2) lib/active_support/inflector/methods.rb:226:in `const_get'
activesupport (4.0.2) lib/active_support/inflector/methods.rb:226:in `block in constantize'
activesupport (4.0.2) lib/active_support/inflector/methods.rb:224:in `each'
activesupport (4.0.2) lib/active_support/inflector/methods.rb:224:in `inject'
activesupport (4.0.2) lib/active_support/inflector/methods.rb:224:in `constantize'
activesupport (4.0.2) lib/active_support/dependencies.rb:535:in `get'
activesupport (4.0.2) lib/active_support/dependencies.rb:566:in `constantize'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:76:in `controller_reference'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:66:in `controller'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:44:in `call'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:680:in `call'