Ruby on rails 改革-访问嵌套表单范围内的父表单参数
我使用的是1.2.6,有一个带验证的嵌套表单 简化:Ruby on rails 改革-访问嵌套表单范围内的父表单参数,ruby-on-rails,ruby,forms,parameters,reform,Ruby On Rails,Ruby,Forms,Parameters,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_
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
class UserForm
参数是正确嵌套的,我只需要一种从嵌套表单访问父表单输入的方法。问题是嵌套表单似乎只能访问其参数集,而不能访问整个参数。因此,基本上,这里真正需要的是使用Dispossible::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
要求“一次性/双胞胎/父母”
类UserForm
此外,您还可以阅读此主题: