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
要修复这个,我必须去routes.rb并更改
resources :media
to
resource :media
and again to
再来一次
resources :media
It's annoying. Any ideas to solve this?
它很烦人。有什么想法解决这个问题?
2 个解决方案
#1
5
You should try new_medium_path
because media
is plural form of medium
您应该尝试new_medium_path,因为媒体是复数形式的媒介
If you run rake routes
you will see all available routes.
如果您运行rake路线,您将看到所有可用的路线。
#2
3
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:
您还可以使用Inflector类通知rails有关正确复数的信息。它处理大多数工作正常,但像“媒体”这样的非标准复数并不总是预先定义的。要添加自己的,请编辑config / initializers / inflections.rb,并在最后添加:
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
这应该让Rails处理所有的复数/单数 - 注意这会影响它认为DB表名也是如此,所以它期望模型为Class Medium,表名将是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
#1
5
You should try new_medium_path
because media
is plural form of medium
您应该尝试new_medium_path,因为媒体是复数形式的媒介
If you run rake routes
you will see all available routes.
如果您运行rake路线,您将看到所有可用的路线。
#2
3
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:
您还可以使用Inflector类通知rails有关正确复数的信息。它处理大多数工作正常,但像“媒体”这样的非标准复数并不总是预先定义的。要添加自己的,请编辑config / initializers / inflections.rb,并在最后添加:
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
这应该让Rails处理所有的复数/单数 - 注意这会影响它认为DB表名也是如此,所以它期望模型为Class Medium,表名将是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