How do I add arbitrary attributes to an AR model? It would appear that simply adding instance vars with accessors to an AR model doesn''t actually work the same way as a regular class. Quite confused by that. The attributes derived by reflection is fine, but I have several other attributes that will not come from the data table. Most are state vars or behavior modification vars derived from config settings or application logic. These + the data table combine to make up the whole model. -- gw --~--~---------~--~----~------------~-------~--~----~ 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 Nov 1, 2007, at 4:18 PM, Greg Willits wrote:> How do I add arbitrary attributes to an AR model? > > It would appear that simply adding instance vars with accessors to an > AR model doesn''t actually work the same way as a regular class. Quite > confused by that. > > The attributes derived by reflection is fine, but I have several > other attributes that will not come from the data table. Most are > state vars or behavior modification vars derived from config settings > or application logic. These + the data table combine to make up the > whole model.Hmm, well after untold permutations, I finally struck upon the combination that works. -- gw --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
attr_accessor :name Basically sets up a getter setter for the attribute so you can do self.name= and self.name. On Nov 1, 4:18 pm, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote:> How do I add arbitrary attributes to an AR model? > > It would appear that simply adding instance vars with accessors to an > AR model doesn''t actually work the same way as a regular class. Quite > confused by that. > > The attributes derived by reflection is fine, but I have several > other attributes that will not come from the data table. Most are > state vars or behavior modification vars derived from config settings > or application logic. These + the data table combine to make up the > whole model. > > -- gw--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---