【发布时间】:2018-04-27 08:36:59
【问题描述】:
我在使用名为 sarlLegalSatuses 的资源的驼峰版本时遇到以下错误
这是我得到的错误:
in check_controller_and_action': 'sarlLegalStatuses' is not a supported controller name. This can lead to potential routing problems.
我的路线:
ils.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'sarlLegalStatuses#new'
resources :sarlLegalStatuses
end
使用蛇形案例解决了这个问题,但是随着我在代码中的进一步深入,这开始很烦人。我注意到人们对以“s”结尾的复数形式的单词有问题,所以我添加了以下变形但没有成功,如你所见:
动作
veSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful'
inflect.uncountable %w(sarl legal)
inflect.irregular 'status', 'statuses'
end
怎么了?
【问题讨论】:
-
你为什么要这样做?你为什么不遵守约定?
-
你能说得更具体些吗,因为我不明白我是怎么不遵守约定的?我正在尝试遵循约定,这就是为什么我不想在我的代码中使用蛇形案例。
-
路由中的
sarlLegalStatuses应该是sarl_legal_statuses并且你的控制器名称应该是sarl_legal_statuses_controller.rb -
只需使用蛇形外壳,就像 Rails 约定 告诉您:
root 'sarl_legal_statuses#new',resources :sarl_legal_statuses -
所以我的问题似乎更像是:“为什么您更喜欢根据您自己的权利的约定,而不是完善并依赖于 Ruby on Rails 框架约定?”
标签: ruby-on-rails ruby-on-rails-5 rails-routing