Search code examples
ruby-on-railsscaffolding

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 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?"

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

Solution

  • There is a railsway of doing this, you can use inflections to document such exceptions:

    config/initializers/inflections.rb

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