Dear list, I''d like to make an ''after_find'' call for each and every AR model I defined. In AWDWR page 376 they do so by opening up the AR class like this: class ActiveRecord::Base def self.some_method return ''foo'' end end All nice and well but where should I store this class?? According to the chapter it should go in app/models. So I placed a file called base.rb in app/models/active_record. To no avail. Placing it in app/ models did no good either. I know I can do this by defining a module in lib/ and include that in all my models but that is just not as pretty. With kind regards, Harm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 4 Dec 2007, at 13:40, harm wrote:> > Dear list, > > I''d like to make an ''after_find'' call for each and every AR model I > defined. In AWDWR page 376 they do so by opening up the AR class like > this: > class ActiveRecord::Base > def self.some_method > return ''foo'' > end > end > > All nice and well but where should I store this class?? According to > the chapter it should go in app/models. So I placed a file called > base.rb in app/models/active_record. To no avail. Placing it in app/ > models did no good either. > > I know I can do this by defining a module in lib/ and include that in > all my models but that is just not as pretty.Put it wherever you want. In environment.rb require that file. An alternative would be class MyBaseClass < ActiveRecord::Base self.abstract_class = true [your funkiness here] end and then have all your classes inherit from MyBaseClass Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Aha! So I should just require it. I was hoping that would go ''automagically''. Thanks for the reply. On Dec 4, 3:02 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 4 Dec 2007, at 13:40, harm wrote: > > > > > > > Dear list, > > > I''d like to make an ''after_find'' call for each and every AR model I > > defined. In AWDWR page 376 they do so by opening up the AR class like > > this: > > class ActiveRecord::Base > > def self.some_method > > return ''foo'' > > end > > end > > > All nice and well but where should I store this class?? According to > > the chapter it should go in app/models. So I placed a file called > > base.rb in app/models/active_record. To no avail. Placing it in app/ > > models did no good either. > > > I know I can do this by defining a module in lib/ and include that in > > all my models but that is just not as pretty. > > Put it wherever you want. In environment.rb require that file. > An alternative would be > > class MyBaseClass < ActiveRecord::Base > self.abstract_class = true > [your funkiness here] > end > > and then have all your classes inherit from MyBaseClass > > Fred--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---