Guðni Hilmarsson
2007-Apr-17 08:33 UTC
Need help iterating over attributes of a Active record object
Hi all... I need help with a little ruby code. I am trying to output every attribute of an actice record object something like: <% for product in @products %> <% for each product.attribute |attribute| %> <p> </p> <% end %> <% end %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bruno Celeste
2007-Apr-17 08:41 UTC
Re: Need help iterating over attributes of a Active record object
product.attributes return a Hash object, so you want: <ul> <% product.attributes.each_pair do |k,v| %> <li><%= k %> => <%= v %></li> <% end %> </ul> On 4/17/07, Guðni Hilmarsson <gudnihilmars-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all... > > I need help with a little ruby code. I am trying to output every > attribute of an actice record object something like: > > <% for product in @products %> > <% for each product.attribute |attribute| %> > <p> > </p> > <% end %> > <% end %> > > > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Guðni Hilmarsson
2007-Apr-17 09:00 UTC
Re: Need help iterating over attributes of a Active record object
Thanks alot mate... On Apr 17, 10:41 am, "Bruno Celeste" <bruno.cele...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> product.attributes return a Hash object, so you want: > > <ul> > <% product.attributes.each_pair do |k,v| %> > <li><%= k %> => <%= v %></li> > <% end %> > </ul> > > On 4/17/07, Guðni Hilmarsson <gudnihilm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi all... > > > I need help with a little ruby code. I am trying to output every > > attribute of an actice record object something like: > > > <% for product in @products %> > > <% for each product.attribute |attribute| %> > > <p> > > </p> > > <% end %> > > <% end %>--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---