Need help iterating over attributes of a Active record objec


#1

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 %>

#2

product.attributes return a Hash object, so you want:

    <% product.attributes.each_pair do |k,v| %>
  • <%= k %> => <%= v %>
  • <% end %>

#3

Thanks alot mate…