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.
This question really is a challenge to my English :D
I googled the noun media, and it says that some purists insist that the word media, which is borrowed from Latin, is the plural form of medium, so from this point of view, Rails generator did the right job.
But in daily English, people simply use media as an uncountable noun or a collective noun. If you agree on that, then adjust the config/initializers/inflections.rb
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.uncountable %w( media )
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With