【发布时间】:2014-04-19 04:33:03
【问题描述】:
我有一个嵌套资源(子),只能在其父资源视图中查看和编辑。当调用child的action并且child无效时,如何让child的错误信息显示在其parent的view上?
为了做到这一点,我现在在父母的控制器中有孩子的动作。但我想将它放在它所属的孩子的控制器中,即我希望在placements_controller 中使用activate 操作,而不是在收件人控制器中使用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.
【问题讨论】:
标签: ruby-on-rails validation model-view-controller view nested-resources