0

My loop:

<% @products.first.attributes.except('name', 'created_at','updated_at','id').each do |attr_name, attr_value| %>
<tr>
    <td><span><%= t(attr_name) %></span></td>
    <td class="middle">Pr. x</td>
    <%= @products.each do |f| %>
    <td class="last"><%= f.attr_name %> ,-</td>
    <% end %>
<tr>
<% end %>

Then I get this error: undefined method attr_name for #<Product:0x3adc850

How do I use the column method with attr_name? I have tried things like f."#{attr_name}" without luck.

4

1 回答 1

1

Use send

<%= @products.each do |f| %>
   <td class="last"><%= f.send attr_name %> ,-</td>
<% end %>

And you should rename f into product (f is generally used for form builders)

于 2013-02-19T19:00:10.913 回答