Forum: Ruby on Rails Need help iterating over attributes of a Active record objec

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B965bae86df56534d608c5938266522c?d=identicon&s=25 Guðni Hilmarsson (Guest)
on 2007-04-17 10:34
(Received via mailing list)
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 %>
D707194949c58eb4076f040adf116508?d=identicon&s=25 Bruno Celeste (Guest)
on 2007-04-17 10:42
(Received via mailing list)
product.attributes return a Hash object, so you want:

<ul>
<% product.attributes.each_pair do |k,v| %>
  <li><%= k %> => <%= v %></li>
<% end %>
</ul>
B965bae86df56534d608c5938266522c?d=identicon&s=25 Guðni Hilmarsson (Guest)
on 2007-04-17 11:01
(Received via mailing list)
Thanks alot mate...
This topic is locked and can not be replied to.