Rail railing is not suitable for a "cafe"

I want to create a cafe and cave controller.

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

rails g scaffold cafe name: string

It displays the plural form of a β€œcafe” as a β€œcave”, which means that I cannot make my controller caves , since the name is already in use.

How to make rails use proper pluralization?

+6
source share
1 answer

You can create your own kinks.

Add this to your config/initializers/inflections.rb

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

(Reboot your server after making the changes. This is not required for the scaffolding command itself, but it is needed when you want to actually view / use the code)

Now, when you run rails g scaffold cafe , you will 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

+15
source

Source: https://habr.com/ru/post/917238/


All Articles