undefined local variable or method `new_media_path' - resources to resource

11,358

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
Share:
11,358
rgtk
Author by

rgtk

Updated on June 17, 2022

Comments

  • rgtk
    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
    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