Is there a way to alias an automaically created model attribute? I have a column named start_time, and when I use alias_method :default_start_time, :start_time In the model''s class definition, I get an "undefined method" error Thanks! Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nope. Attribute access is implemented through method_missing, which means that the method you''re trying to alias just won''t exist. You can still alias things the "long" way: def default_start_time start_time end or on one line, if you prefer: def default_start_time; start_time end Daniel Higginbotham wrote:> Is there a way to alias an automaically created model attribute? I have a > column named start_time, and when I use > > alias_method :default_start_time, :start_time > > In the model''s class definition, I get an "undefined method" error > > Thanks! > Daniel > > > >-- Lance Ivy Web Applications Developer RBS Interactive lance.ivy-eTT0+Q0rEURLdZBKzJmsdNBPR1lH4CV8@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 10/19/06, Daniel Higginbotham <daniel-4cOk6EWy6wjNj93mkU9IYrqjc7CnNF17@public.gmane.org> wrote:> > Is there a way to alias an automaically created model attribute? I have a > column named start_time, and when I use > > alias_method :default_start_time, :start_time > > In the model''s class definition, I get an "undefined method" errorTry alias_attribute. jeremy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Lance Ivy wrote:> Nope. Attribute access is implemented through method_missingReally? Looking at the source, method_missing is used for dynamic finders. Joe -- 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 -~----------~----~----~----~------~----~------~--~---
Yeah, it''s easy enough to miss: the method_missing defined on line 1090 (activerecord 1.14.4, base.rb) implements the dynamic finders for the class, and the method_missing defined further down on line 1770 implements attribute access for the instances. They''re used in different contexts (e.g. Person.find_by_first_name vs person.first_name). Joe Ruby MUDCRAP-CE wrote:> Lance Ivy wrote: > >> Nope. Attribute access is implemented through method_missing >> > > Really? Looking at the source, method_missing is used for dynamic > finders. > > Joe > >-- Lance Ivy Web Applications Developer RBS Interactive lance.ivy-eTT0+Q0rEURLdZBKzJmsdNBPR1lH4CV8@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks everyone! On Thursday 19 October 2006 8:34 am, Jeremy Kemper wrote:> On 10/19/06, Daniel Higginbotham <daniel-4cOk6EWy6wjNj93mkU9IYrqjc7CnNF17@public.gmane.org> wrote: > > Is there a way to alias an automaically created model attribute? I have > > a column named start_time, and when I use > > > > alias_method :default_start_time, :start_time > > > > In the model''s class definition, I get an "undefined method" error > > Try alias_attribute. > > jeremy > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---