Problem with AR and 'virtual' multiparameter attributes

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

On Dec 11, 1:39 pm, Joel N. [email protected]
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
http://lindsaar.net/

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:inexecute_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:inattributes=’
/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:ininitialize’
/app/controllers/tasks_controller.rb:534:in create' /lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:inperform_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:incall_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:incall_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:incall_filter’
/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:438:in
`call’

thanks
Joel

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs