Rails scaffolding pluralisation is incorrect for “cafe”

后端 未结 1 884
独厮守ぢ
独厮守ぢ 2021-02-04 18:59

I want to create a cafe and a cave controller.

When I try to create my cafe using rails scaffolding, via the command

相关标签:
1条回答
  • 2021-02-04 19:25

    You can create your own inflections.

    Add this to your config/initializers/inflections.rb

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

    (Restart your server after making this change. This is not required for the scaffolding command itself but it will be required when you want to actually view/use the code)

    Now when you run rails g scaffold cafe you'll get:

    ...
    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
    

    This may help you: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-inflections

    0 讨论(0)
提交回复
热议问题