On Nov 8, 8:04 am, Ryoichiro Kamiya <[email protected]>
wrote:
> Hi,
>
> I am trying to set initial process when instantiating model by  
> overriding initialize() method which takes arguments. The initialize()  
> method overrides the parent ActiveRecord::Base class's by taking  
> arguments and assign arguments to its instance variables.
>
> class Product < ActiveRecord::Base
>
>    def initialize(item = nil)
>      super
>      # and then process to assign variables from item argument to  
> instance variables
>      # ....
>    end


What does the actual code in there look like? What is the error that
you get ?

Fred

>
> In order to fully leverage ActiveRecord::Base class functionality, I'm  
> calling super to run the default initialization process (i.e. set up  
> all setter/getter methods). However, the Product class above still  
> can't find getter/setter methods for its variables. In the meantime, I  
> found the following blog article suggesting use after_initialize  
> instead of overriding Active Record object.
>
> Rails: Don't override initialize on ActiveRecord 
> objectshttp://blog.dalethatcher.com/2008/03/rails-dont-override-initialize-o...
>
> I could not find ways to set arguments for this after_initialize  
> approach.
>
> Can anybody advise should I override initialize() or use  
> after_initialize with some ways to take arguments?
>
> Thanks,
> Ryo
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to