Rob Rob - 1 year ago 98
Ruby Question

undefined method `value' for #<CategoryItemValue::ActiveRecord_Associations_CollectionProxy:0x007ff9706d24c0>

This is so simple but isnt working. What am I missing?


@guide = Guide.friendly.find(params[:guide_id])
@category = @guide.categories.friendly.find params[:id]
@items = @category.category_items


<% @items.each do |item| %>
<%= item.category_item_values.value %>
<% end %>

gives the no method error of

undefined method 'value' for #<CategoryItemValue::ActiveRecord_Associations_CollectionProxy:0x007ff9706d24c0>

There is a
column in the
table so I'm not sure what the problem is.

Answer Source

item.category_item_values is the CollectionProxy instance (one might think of it as of an kinda array.)

Each category_item has [likely, you did not provide sufficiently enough info to guess more precisely] many values. If the assumption above is correct, here you go:

<% @items.each do |item| %>
  <% item.category_item_values.each do |value| %>
    <%= value %> # or maybe (depending on your model) <%= value.value %>
  <% end %>
<% end %>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download