【发布时间】:2013-01-14 19:37:48
【问题描述】:
当我使用路径 edit_projects_proj_paquet_mesures_proj_mesure_path() 时,我的 form_for 视图中出现以下错误:
undefined method `projects_proj_mesure_path' for #<#<Class:0xac942e4>:0xac9d1f0>
当我使用路径 new_projects_proj_paquet_mesures_proj_mesure_path() 时不会出现此错误。
虽然我将我的资源定义为嵌套在我的 config/route.rb
中的命名空间namespace :projects do
resources :proj_paquets_mesures do
resources :proj_mesures
end
end
按照stackoverflow question-answer 中的建议,我的 _form.html.haml 以 :
开头form_for([:projects, @proj_paquet_mesures, @proj_mesure], :html => {:class => "formulaire-standard"}) do |f|
...
请注意在 config/initializer/inflection.rb 中设置了异常:
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'proj_paquet_mesures', 'proj_paquets_mesures'
end
当我对资源使用 Shallow 选项并使用路径 projects_proj_mesure_path() 时,一切正常:
namespace :projects do
resources :proj_paquets_mesures, :shallow => true do
resources :proj_mesures
end
end
【问题讨论】:
标签: namespaces ruby-on-rails-3.2 form-for nested-resources