看到一个使用form_for与嵌套资源的问题,我已经重新映射路由更明智。form_for嵌套资源路由问题
我的routes.rb:
resources :books do
resources :sections, :controller => 'content_sections'
member do
post 'publish'
end
end
而且我_form.html.haml
= form_for [@book, @content_section] do |f|
-if @content_section.errors.any?
#error_explanation
%h2= "#{pluralize(@content_section.errors.count, "error")} prohibited this section from being saved:"
%ul
- @content_section.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :name
= f.text_field :name
这是造成此错误:
undefined method `book_content_sections_path' for #<#<Class:0x00000103a58238>:0x00000103a4a0e8>
什么我期待的book_sections_path
但它没有考虑到routes.rb中的设置。
请加耙路输出 –