I have a rails form with a datetime_select field. When I try to submit the form, I get the following exception:
ActiveRecord::MultiparameterAssignmentErrors in WidgetsController#update
1 error(s) on assignment of multiparameter attributes
If it's a validation error, why don't I see an error on the page?
This is in Rails 2.0.2
This error can also occur with webrat/cucumber when filling in form data using a table.
eg this doesn't work:
but this does:
Super hack, but I needed to solve this problem right away for a client project. It's still a bug with Rails 2.3.5.
Using either
date_select
ordatetime_select
, if you add this to your model in theinitialize
method, you can pre-parse the passed form-serialized attributes to make it work:I am using this with a nested, polymorphic, model. Here's a question I had showing the models I'm using. So I needed
accepts_nested_attributes_for
with a datetime.Here's the input and output using the console:
Otherwise it was either null, or it would throw the error:
1 error(s) on assignment of multiparameter attributes
Hope that helps, Lance
Like Zubin I've seen this exception when the form submits a month as a month name rather than a numerical month string (eg. October rather than 10).
One user agent I've encountered seems to submit the contents of the option tag rather than the value attribute:
So in the case of submitting a multi-parameter date from a helper generated select (from date_select helper) your params will have:
This creates an exception: ActiveRecord::MultiparameterAssignmentErrors: 1 error(s) on assignment of multiparameter attributes
Most user agents will correctly submit:
In my case the ActiveRecord am/pm plugin caused the error through an incorrect
alias_method_chain
resulting in anStackLevelTooDeep
exception.The plugin was included by the unobtrusive_date_picker plugin.
The look into this before hacking away.
ActiveRecord throws the MultiparameterAssignmentErrors exception when you try to set an invalid date to a models attribute.
Try to pick a Nov 31 date from the date_select or datetime_select dropdown and you will get this error.
This is not a bug in Rails, it is the intended behavior of the multi-parameter attribute writer. I'm willing to bet that the original poster's deliver_date field in the database is a varchar as opposed to a date or datetime type. ActiveRecord uses each part of the multi-parameter attribute to send to the new method of the serialized type. The number 1, 2, 3, etc indicates the constructor parameter position and the "i" tells ActiveRecord to call to_i on the parameter before passing it to the constructor. In this case they are all "i's" because DateTime.new(year, month, day) expects three Integers not three Strings.
If the deliver_date column in the database isn't a type that's serialized to a DateTime then ActiveRecord will throw a ActiveRecord::MultiparameterAssignmentErrors exception because String.new(2010,2,11) won't be successful.
Source: https://github.com/rails/rails/blob/v3.0.4/activerecord/lib/active_record/base.rb#L1739