Not even sure I have the right terminology here, Ruby/Rails syntax is a bit of a challenge to get my brain wrapped around. The majority of my models will have a timestamp/userstamp (updated_on, updated_by) type thing. I haven''t really settled on an authentication method yet, but was wondering how I might add this in a DRY fashion to my models. I looked at the userstamp plugin, but I don''t want foreign keys, and I want to learn how to roll this myself. What''s the best ruby-esque way to achieve this? Would I somehow construct a standard decorator for the model? Would I subclass a base record somehow, check for the existance of the fields and stuff them? I know I could do this on a model by model basis using a before_update type thing, but how do I DRY it? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ljredpath-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-04 18:03 UTC
Re: Subclassing Models
Use a mixin. On Feb 4, 5:35 pm, "Meech" <Meech...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Not even sure I have the right terminology here, Ruby/Rails syntax is > a bit of a challenge to get my brain wrapped around. > > The majority of my models will have a timestamp/userstamp (updated_on, > updated_by) type thing. I haven''t really settled on an > authentication method yet, but was wondering how I might add this in a > DRY fashion to my models. I looked at the userstamp plugin, but I > don''t want foreign keys, and I want to learn how to roll this myself. > > What''s the best ruby-esque way to achieve this? > > Would I somehow construct a standard decorator for the model? > Would I subclass a base record somehow, check for the existance of the > fields and stuff them? > > I know I could do this on a model by model basis using a before_update > type thing, but how do I DRY it?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
unknown wrote:> Use a mixin.Also be aware that Rails gives you created_[at|on] and updated_[at|on] functionality for free. If those fields exist, rails will fill them in form you. the _on variety is a DATE filed, the _at variety is a DATETIME field. The user stuff you''ll need to do yourself. A. -- 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 -~----------~----~----~----~------~----~------~--~---