1
我有一個嵌套資源(子),只能在其父資源視圖上查看和編輯。如何在孩子的動作被調用且孩子無效時在其父視圖上顯示孩子顯示的錯誤消息?在其父資源視圖中顯示嵌套資源的錯誤消息
爲了做到這一點,我現在在父母的控制器中有孩子的行爲。但是我希望將它放在它所屬的孩子的控制器中,即我希望placements_controller中的activate
操作,而不是recipients_controller中的activate_placement
操作。
的routes.rb:
# Present setup:
patch '/recipients/:recipient_id/placements/:id/activate' =>
'recipients#activate_placement', :as => :activate_recipient_placement
# Placement is activated (and validated) by recipients_controller.
# If errors exist, recipient's show view with that placement is rendered
# displaying the placement's error messages. I want that.
# But I'd like the activate action to be in the placements_controller.
# Preferred setup:
resources :recipients do
...
resources :placements do
patch 'activate' on: :member
end
end
# Now, placement is activated (and validated) by placements_controller.
# But if errors exist on the placement, the placement's own show view,
# rather than the parent's show view, is rendered with the error messages.
謝謝,豐富的,我說的routes.rb代碼。請讓我知道是否需要更多。 – Arta