# MultiparameterAssignmentErrors when feeding a bogus day/month combination into a date\_select--how be

**URL:** <https://www.ruby-forum.com/t/multiparameterassignmenterrors-when-feeding-a-bogus-day-month-combination-into-a-date-select-how-be/146296>\
**Category:** Rails\
**Created:** [August 19, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/multiparameterassignmenterrors-when-feeding-a-bogus-day-month-combination-into-a-date-select-how-be/146296 "2008-08-19T21:13:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpardee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rpardee](https://www.ruby-forum.com/u/rpardee)\
**Post date:** [August 19, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/multiparameterassignmenterrors-when-feeding-a-bogus-day-month-combination-into-a-date-select-how-be/146296/1 "2008-08-19T21:13:19Z")

</div>

Hey All,

My user just got bit by this problem (in my rails version 2.0.2 app):

[http://railsmanual.com/class/ActiveRecord::MultiparameterAssignmentErrors](http://railsmanual.com/class/ActiveRecord::MultiparameterAssignmentErrors)

That is, if you use the date\_select generated list boxes to select a  
nonexistant date like say, April 31st, you get a stack trace like this  
here:

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/base.rb:2397:in  
`execute_callstack_for_multiparameter_attributes' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2377:in `assign\_multiparameter\_attributes’  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active\_record/base.rb:2120:in  
`attributes=' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2033:in `update\_attributes’  
app/controllers/projects\_controller.rb:76:in `update' app/controllers/projects_controller.rb:75:in `update’

You get the same exception if you

So… is there some particularly good place to fix this? I can  
certainly pull the date components out of params[] in my controller, try  
a Date.parse() on them & give the user a better error message. But I’ve  
got date\_select’s in lots of different places in my app & would love it  
if I could just fix it in one spot…

I’ve looked in the attributes=() method in ar:base, but am a bit daunted  
by it–have a hard time imagining I’m going to do more good than harm in  
there… ☹

Anybody got ideas for me?

Thanks!

-Roy

Roy P.  
Research Analyst/Programmer  
Group Health Center For Health Studies (Cancer Research Network)  
(206) 287-2078  
Google Talk: rpardee

---

<div class="post-metadata">

**Author:** ![rpardee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rpardee](https://www.ruby-forum.com/u/rpardee)\
**Post date:** [August 19, 2008, 11:06pm UTC](https://www.ruby-forum.com/t/multiparameterassignmenterrors-when-feeding-a-bogus-day-month-combination-into-a-date-select-how-be/146296/2 "2008-08-19T23:06:42Z")

</div>

This seems to work, but it’s hardly DRY:

def update  
@project = Project.find(params[:id])  
respond\_to do |format|  
begin  
if @project.update\_attributes(params[:project])  
flash[:notice] = ‘Project was successfully updated.’  
format.html { redirect\_to(@project) }  
format.xml { head :ok }  
else  
format.html { render :action =\> “edit” }  
format.xml { render :xml =\> @project.errors, :status =\>  
:unprocessable\_entity }  
end  
rescue ActiveRecord::MultiparameterAssignmentErrors  
@project.errors.add(“end\_date” , “May be bogus”)  
@project.errors.add(“start\_date”, “May be bogus”)  
format.html { render :action =\> “edit” }  
format.xml { render :xml =\> @project.errors, :status =\>  
:unprocessable\_entity }  
end  
end  
end

I’d have to repeat that for every update and create action 😛

It looks like the root cause is that Date.new(), unlike other  
constructors in ruby (I think?), throws an ArgumentError exception if  
you give it something it doesn’t understand. The others seem to give a  
default value (e.g., 0 for integers, false for booleans).

I dug a little deeper in ar:base.rb–still don’t see a good place to  
muck around in there. ☹
