Shankar Narayanan
2008-Jul-07 11:29 UTC
Identifying the attributes of an object dynamically
Hello I have an object ''details'' which comprises of many attributes like name address.city address.state department.name For a given object of ''details'', I am trying to obtain the values of some attributes from a given list ("name","department.name "), say from the config. I tried iterating over the list and access the object''s attrib using instance_variable_get, but ended up with the error (["name"] is not a symbol) Is there something incorrect that I am trying to do ? ~Shankar. -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jul-07 11:40 UTC
Re: Identifying the attributes of an object dynamically
On 7 Jul 2008, at 12:29, Shankar Narayanan wrote:> > Hello > > I have an object ''details'' which comprises of many attributes like > > name > address.city > address.state > department.name > > For a given object of ''details'', I am trying to obtain the values of > some attributes from a given list ("name","department.name "), say > from > the config. I tried iterating over the list and access the object''s > attrib using instance_variable_get, but ended up with the error >Assuming you are talking about an ActiveRecord object, database attributes are not instance variables. attributes surprisingly enough contains all the attributes. Fred> (["name"] is not a symbol) > > Is there something incorrect that I am trying to do ? > > ~Shankar. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Shankar Narayanan
2008-Jul-07 11:46 UTC
Re: Identifying the attributes of an object dynamically
Frederick Cheung wrote:> Assuming you are talking about an ActiveRecord object, database > attributes are not instance variables. attributes surprisingly enough > contains all the attributes. > > FredAh! yes.. thanks for pointing that out, Fred. But is there something like ''attributes_get'' that I should be using to get the values of the attribute in my case ? ~Shankar. -- 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 -~----------~----~----~----~------~----~------~--~---
Shankar Narayanan
2008-Jul-07 12:46 UTC
Re: Identifying the attributes of an object dynamically
> Ah! yes.. thanks for pointing that out, Fred. But is there something > like ''attributes_get'' that I should be using to get the values of the > attribute in my case ? > > ~Shankar.Aww.. was really a very dumb question to ask... :( object.attributes[<attr_name>] would obviously give the value.. Thanks for the help, Fred. Appreciate it !! ~Shankar. -- 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 -~----------~----~----~----~------~----~------~--~---