简体   繁体   English

导轨脚手架不复数生成

[英]rails scaffold not plural generate

I would like to generate a scaffolded controller, view and helper named with not pluraled one, but singular one. 我想生成一个脚手架的控制器,视图和助手,其名称不是复数,而是单数。 Howevery, I got pluraled named files like below. 但是,我得到了多个如下所示的命名文件。 I know they are based on the rails convention, but I just would like to create a dictionary page. 我知道它们基于rails约定,但是我只想创建一个词典页面。

$ rails generate scaffold_controller dictionary
  create  app/controllers/dictionaries_controller.rb
  invoke  erb
  create    app/views/dictionaries
  create    app/views/dictionaries/index.html.erb
  create    app/views/dictionaries/edit.html.erb
  create    app/views/dictionaries/show.html.erb
  create    app/views/dictionaries/new.html.erb
  create    app/views/dictionaries/_form.html.erb
  invoke  helper
  create    app/helpers/dictionaries_helper.rb

So, my question is "Are there any better ways or the shortest way to generate a singular named controller/view/helper files by command?" 因此,我的问题是“是否有更好的方法或最短的方法通过命令生成命名为controller / view / helper的单个文件?”

What I want is just below. 我想要的只是下面的。 I'm wondering if I should make the files manually? 我想知道是否应该手动制作文件?

  app/controllers/dictionary_controller.rb
  app/views/dictionary/index.html.erb
  app/helpers/dictionary_helper.rb

There is a railsway of doing this, you can use inflections to document such exceptions: 这样做是有道理的,您可以使用inflections来记录此类异常:

config/initializers/inflections.rb config / initializers / inflections.rb

ActiveSupport::Inflector.inflections do |inflect|
  inflect.uncountable "dictionary"
end

Well without messing with any thing in rails you can set up the routes using resource instead of resources more about that here 那么在没有护栏的任何事情搞乱你可以使用设置路由resource ,而不是resources 更多,在这里

You'll still use a plural controller name ( if you need processing ), but the URL will be singular, and you won't have all the actions like the plural resources ( more about that in the link ), if you just want one page then limit by using only: :show 您仍将使用复数控制器名称(如果需要处理),但是URL将是单数,并且如果您只想要一个,则不会有像复数resources类的所有操作(有关链接的更多信息)。页,然后only: :show使用限制only: :show

resource :dictionary, only: :show

Then you don't even need the contorller, just create the file dictionaries/show.html.haml (or erb) and it would work 然后,您甚至不需要控制器,只需创建文件dictionaries/show.html.haml (或erb)即可,

http://example.com/dictionary

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM