Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 898
rgtk Avatar asked Mar 24 '12 14:03

rgtk


2 Answers

You should try new_medium_path because media is plural form of medium

If you run rake routes you will see all available routes.

like image 66
Sergey Kishenin Avatar answered Nov 04 '22 20:11

Sergey Kishenin


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
like image 38
Elocution Safari Avatar answered Nov 04 '22 21:11

Elocution Safari