看到一個使用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中的設置。
請加耙路輸出 –