我有一个使用此处定义的模式的表单对象:https ://forum.upcase.com/t/form-objects/2267
class RegistrationForm
include ActiveModel::Model
attr_accessor :first_name, :last_name, :date_of_birth
...
end
与该示例不同,我的表单中的一个基础模型有一个日期字段。该日期字段以简单形式呈现为多参数属性,并通过以下方式提交给控制器:
"user"=>
{"first_name"=>"Hanna",
"last_name"=>"Macias",
"date_of_birth(1i)"=>"2016",
"date_of_birth(2i)"=>"2",
"date_of_birth(3i)"=>"26",
...
但是,我在控制器上的操作中遇到unknown attribute 'date_of_birth(1i)' for RegistrationForm.
错误:RegistrationForm.new(registration_params)
#create
def create
@registration = RegistrationForm.new(registration_params)
if @registration.save
redirect_to root_path
else
render 'new'
end
end
private
def registration_params
params.require(:registration).permit!
end
我已经尝试attr_accessor
为 等定义额外的 s :date_of_birth_1i, :date_of_birth_2i, :date_of_birth_3i
,但这并没有解决问题。
我需要做什么才能正确处理多参数属性?