I'm working with Rails 5 an I just have created a Media
model using scaffold tool.
rails g scaffold media name:string
And I got different names and routes and view etc...
It was not right pluralising, so when I rake routes
I got medium
unexpected routes and because of that I got different problems in the views.
When I try to use <%= form_for @media do ..
I got complain about no method media_index_path
.
How can I get it fixed and working well?
Searching all day about this and being a little bit more curious when I run the very first scaffold it recommended to use something called inflections
which basically is in charge of the pluralising and singularising words for class names:
What I did to get it fixed was to use inflections
in the next way:
Delete the model I just have created.
rails d scaffold Media
Edit config/initializers/inflections.rb
with:
ActiveSupport::Inflector.inflections(:en) do |inflect|
# Here you can put the singular and plural form you expect
inflect.irregular 'media', 'medias'
end
Now execute the scaffold again:
rails g scaffold Media
Now you must have everything in the way you expected. Because you have overwritten the Pluralizations and Singularizations (Inflections) in Ruby on Rails.
I hope it could be useful.