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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Guðni Hilmarsson (Guest)
on 2007-04-17 12: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|  %>
    <% end %>
<% end %>
Bruno C. (Guest)
on 2007-04-17 12:42
(Received via mailing list)
product.attributes return a Hash object, so you want:

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