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 do |shop| %>
<% @deliveries.each do |dlv| %>
<div><%= dlv.shop.type %></div>
<%end%>
<% end %>
getting an error
undefined method `type’ for “#”:Shop
I am printing data from table Shops and for each item from this table I want to display items from tabe “Deliveries”. I though the associations are right, but if I am getting the error above, I am not so sure already…
I would like to ask you about help, what could be wrong. Thank you in advance.
The point of associations is that you can access it from an instance of the model. Note, that
has_manyassociations should be pluralized.