Rails脚手架多元化对于“咖啡馆”不正确

我想创建一个cafe和一个cave控制器。

当我尝试使用rails scaffolding创建我的cafe ,通过命令

rails g scaffold cafe name:string

它将复数forms的“咖啡馆”推导为“洞穴”,这意味着我不能制作我的caves控制器,因为该名称已被使用。

如何使轨道使用正确的复数?

您可以创建自己的变形。

将其添加到config/initializers/inflections.rb

  ActiveSupport::Inflector.inflections do |inflect| inflect.plural "cafe", "cafes" end 

(进行此更改后重新启动服务器。这对于脚手架命令本身不是必需的,但是当您想要实际查看/使用代码时将需要它)

现在,当你运行rails g scaffold cafe你会得到:

 ... app/views/cafes create app/views/cafes/index.html.erb create app/views/cafes/edit.html.erb create app/views/cafes/show.html.erb create app/views/cafes/new.html.erb create app/views/cafes/_form.html.erb etc 

这可能对您有所帮助: http : //api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-inflections