我使用的是Reform 1.2.6,并且有一个带有验证的嵌套表单
简化版:
class UserForm < Reform::Form
property :date_of_birth
property health_profile do
property :diagnosed_with_condition_at
validate :diagnosed_date
def diagnosed_date
# need to get access to date_of_birth here
# validate that diagnosed_with_condition_at is after date of birth
end
end
end参数是嵌套的,我只需要一种方法来访问嵌套表单中的父表单输入。问题是嵌套表单似乎只能访问它的参数集,而不是整个参数。
发布于 2017-12-13 21:52:06
因此,基本上您在这里真正需要的是使用Disposable::Twin::Parent特性。
require 'disposable/twin/parent'
class UserForm < Reform::Form
feature Disposable::Twin::Parent
property :date_of_birth
property health_profile do
property :diagnosed_with_condition_at
validate :diagnosed_date
def diagnosed_date
self.parent.date_of_birth
end
end
end此外,您还可以阅读此主题:https://github.com/apotonick/disposable/issues/61
https://stackoverflow.com/questions/46185232
复制相似问题