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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Joel Nylund
2007-Dec-11 02:39 UTC
Re: problem with AR and ''virtual'' multiparameter attributes.
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, > > -JamesHi, 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mikel
2007-Dec-28 00:57 UTC
Re: problem with AR and ''virtual'' multiparameter attributes.
On Dec 11, 1:39 pm, Joel Nylund <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---