What Does ActiveRecord::MultiparameterAssignmentErrors Mean?

后端 未结 7 641
[愿得一人]
[愿得一人] 2020-12-15 22:46

I have a rails form with a datetime_select field. When I try to submit the form, I get the following exception:

ActiveRecord::MultiparameterAssignmentErrors          


        
7条回答
  •  庸人自扰
    2020-12-15 23:27

    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

提交回复
热议问题