# Problem with AR and 'virtual' multiparameter attributes

**URL:** <https://www.ruby-forum.com/t/problem-with-ar-and-virtual-multiparameter-attributes/107484>\
**Category:** Rails\
**Created:** [June 22, 2007, 5:32am UTC](https://www.ruby-forum.com/t/problem-with-ar-and-virtual-multiparameter-attributes/107484 "2007-06-22T05:32:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![james](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@james](https://www.ruby-forum.com/u/james)\
**Post date:** [June 22, 2007, 5:32am UTC](https://www.ruby-forum.com/t/problem-with-ar-and-virtual-multiparameter-attributes/107484/1 "2007-06-22T05:32:21Z")

</div>

Hello,

I have a model which I would like to have a ‘virtual’ date column.  
This column wouldn’t exist in the database, but would exist for  
validation, etc. The data would be provided in the form of a  
date\_select in the view. This produces a multiparameter attribute. My  
problem is that the ‘execute\_callstack\_for\_multiparameter\_attributes’  
method in base.rb of ActiveRecord looks at the columns array to  
determine the ‘class’ (klass) to use when doing the multiparameter  
conversion. Since this column doesn’t really exist nothing is found  
and an exception is thrown when trying to evaluate nil.klass.

I’m willing to provide a patch, but I am not what would be the best  
way to provide the type information. Any suggestions?

Thanks,

-James

---

<div class="post-metadata">

**Author:** ![james](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@james](https://www.ruby-forum.com/u/james)\
**Post date:** [December 28, 2007, 1:57am UTC](https://www.ruby-forum.com/t/problem-with-ar-and-virtual-multiparameter-attributes/107484/2 "2007-12-28T01:57:53Z")

</div>

On Dec 11, 1:39 pm, Joel N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > I’m willing to provide a patch, but I am not what would be the best  
> > way to provide the type information. Any suggestions?

Did you end up writing anything? Running into this problem myself and  
am handling it with the controller re-writing the params[:hash] as an  
“instant” fix.

I’ll look into it as well if you haven’t.

Mikel

> **[Mikel Lindsaar](https://lindsaar.net/)**
>
> Internet Home for Mikel Lindsaar

---

<div class="post-metadata">

**Author:** ![james](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@james](https://www.ruby-forum.com/u/james)\
**Post date:** [December 11, 2007, 3:39am UTC](https://www.ruby-forum.com/t/problem-with-ar-and-virtual-multiparameter-attributes/107484/3 "2007-12-11T03:39:15Z")

</div>

James wrote:

> Hello,
> 
> I have a model which I would like to have a ‘virtual’ date column.  
> This column wouldn’t exist in the database, but would exist for  
> validation, etc. The data would be provided in the form of a  
> date\_select in the view. This produces a multiparameter attribute. My  
> problem is that the ‘execute\_callstack\_for\_multiparameter\_attributes’  
> method in base.rb of ActiveRecord looks at the columns array to  
> determine the ‘class’ (klass) to use when doing the multiparameter  
> conversion. Since this column doesn’t really exist nothing is found  
> and an exception is thrown when trying to evaluate nil.klass.
> 
> I’m willing to provide a patch, but I am not what would be the best  
> way to provide the type information. Any suggestions?
> 
> Thanks,
> 
> -James

Hi, I have this same issue, it looks like the  
execute\_callstack\_for\_multiparameter\_attributes assumes that all  
muti-parameter attributes are persistent.

the code in there is way over my head also, does anyone have suggestions  
of how to get this to work? or an elegant work around? (for now im going  
to roll my own time\_select helper I guess)

To reproduce this issue, add attr\_accessor :foo to any active record and  
then try to use a helper that is multi parameter (time,date etc) like  
time\_select on it. On submit you will get:

NoMethodError (You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.klass):  
/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:2082:in  
`execute_callstack_for_multiparameter_attributes' /lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:2081:in`execute\_callstack\_for\_multiparameter\_attributes’  
/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:2074:in  
`assign_multiparameter_attributes' /lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1675:in`attributes=’  
/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:1505:in  
`initialize_without_callbacks' /lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:225:in`initialize’  
/app/controllers/tasks\_controller.rb:534:in `create' /lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in`perform\_action\_without\_filters’  
/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:632:in  
`call_filter' /lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:638:in`call\_filter’  
/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:438:in  
`call' /lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:637:in`call\_filter’  
/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:634:in  
`call_filter' /lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:638:in`call\_filter’  
/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:438:in  
`call’

thanks  
Joel
