I have a case where I am abstracting the creation of models. After a fair bit of indirection, I eventually get around to making a .new call. I need to be able to pass params to that .new call. I know I can''t use def initialize() in an AR model (rather frustrating). So, I have found some references to after_initialize, but that doesn''t work either. I see several threads on people trying to use after_initialize, but no conclusive answers to the same errors I am seeing -- undefined method `stringify_keys! Example refc: http://www.ruby-forum.com/topic/86173 My after_initialize is just this simple code: def after_initialize(asset_path) @asset_path = asset_path end So either a) what is the proper technique for using after_initialize, or b) is there another way I can pass params to an AR model in a .new call ? Thx. -- greg willits -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Greg Willits wrote: [...]> So either a) what is the proper technique for using after_initialize, or > b) is there another way I can pass params to an AR model in a .new call > ?Can''t you just call Model.new(:the => ''params'', :go => ''here'') ?> > Thx. > > -- greg willitsBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> [...] >> So either a) what is the proper technique for using after_initialize, or >> b) is there another way I can pass params to an AR model in a .new call >> ? > > Can''t you just call Model.new(:the => ''params'', :go => ''here'') ?<smack> I''ve never used that form, but I should have remembered it. For my immediate need that won''t work, but that''s a function of the domain problem in this instance (turns out what I wanted can''t be solved by passing params into new anyway). For general purpose needs, that would probably work, so I''ll implement it in the API for this abstrated system to at least support passsing attributes upon a new(). Thx. -- gw -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.