activerecord - Rails 3 - problem with associations -
i have following structure:
class delivery < activerecord::base belongs_to :shop end
and
class shop < activerecord::base has_many :delivery end
and in view
<% @shops.each |shop| %> <% @deliveries.each |dlv| %> <div><%= dlv.shop.type %></div> <%end%> <% end %>
getting error
undefined method `type' "#":shop
i printing data table shops , each item table want display items tabe "deliveries". though associations right, if getting error above, not sure already...
i ask help, wrong. thank in advance.
<% @shops.each |shop| %> <% shop.delivery.each |dlv| %> <div><%= dlv.type %></div> <%end%> <% end %>
the point of associations can access instance of model. note, has_many
associations should pluralized.
Comments
Post a Comment