Wednesday, January 2, 2013

Fix for 1 error(s) on assignment of multiparameter attributes rails

I have a form that submits dates like so in the params hash:

{
"dob(1i)" => "01",
"dob(2i)" => "02",
"dob(3i)" => "2011"
}

and I started getting

1 error(s) on assignment of multiparameter attributes rails.

 What I did to fix this, was in the controller action, I took the params object:

 dobs = params.delete("dob").split(/[\D]/)

  params["dob"] = Time.new(dobs[2], dobs.first, dobs[1])

When update is called on these params, it will work just fine. It's a hacky work around, but a work around it is. It splits the date on a non-numeric delimiter(/, -, what have you) and then makes a new Time object.

You're welcome.