undefined local variable or method `new_media_path' - resources to resource
Solution 1
You should try new_medium_path
because media
is plural form of medium
If you run rake routes
you will see all available routes.
Solution 2
You can also inform rails about the proper pluralization using the Inflector class. It handles most works fine, but non-standard pluralizations like 'media' aren't always pre-defined. To add your own, edit config/initializers/inflections.rb, and add this at the end:
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'medium', 'media'
end
This should let Rails handle all the plural/singular stuff - note this will affect that it thinks DB table names will be as well, so it'll expect the model to be class Medium, and the table name will be media
To turn the plural and singular to the same thing (i.e. always 'media'), use:
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable 'media'
end
rgtk
Updated on June 17, 2022Comments
-
rgtk almost 2 years
I have odd problem:
After starting server I got this error:
undefined local variable or method `new_media_path'
To repair this i must go to routes.rb and change
resources :media
to
resource :media
and again to
resources :media
It's annoying. Any ideas to solve this?
-
Shaun about 12 years..or change the routes to resources :medias. Not proper English, but it would give you "media" as the singluar, if you like