有一个嵌套的形式中,该关系是像这样嵌套窗体 - 如何基于子模型上的输入验证父模型?
class Inspection < ActiveRecord::Base
has_many :inspection_components
accepts_nested_attributes_for :inspection_components
class InspectionComponent < ActiveRecord::Base
belongs_to :inspection
我在检查一个自定义的验证方法,其取决于为InspectionComponent输入的属性。我如何验证 - InspectionComponent属性在检验验证中未保存或可用。
谢谢!
编辑:为了让事情更清楚些,下面是我想要做的一个例子。
检查具有属性状态。 InspectionComponent也有一个属性状态。
检查编辑表单嵌套了InspectionComponents,并且可以更新此表单上的每个模型的状态。如果@ inspection_component.status =='complete',@ inspection.status应该只能标记为'complete'。
因此,在验证@inspection时,我必须能够看到用户为@ inspection_component.status输入的内容。
很明显,我可以访问控制器中两个实例的参数,但是在应该进行验证的模型中,我没有看到实现这种情况的方法。
希望这很清楚,谢谢。
我的回答有帮助吗? – DJTripleThreat 2010-09-11 07:54:46
这是的,但它没有解决整个问题,请在下面的帖子下面看到我的评论。谢谢。 – 46and2 2010-09-12 06:41:55