I have the following models:
class Entity < ActiveRecord::Base ... has_many :locations, :dependent => :destroy, :include => :sites
has_many :sites, :through => :locations
class Site < ActiveRecord::Base
has_many :locations has_many :entities, :through => :locations
class Location < ActiveRecord::Base
belongs_to :entities belongs_to :sites
In views/entities/index.html.erb I have this:
<% if entity.locations.empty? -%> <%= link_to 'Add Locations', new_entity_locations_path(entity) -%> <% else -%> <%= link_to 'Edit Locations', entity_locations_path(entity) -%> <% end -%>
And in entities_controller.rb I have this:
10 def index 11 @entities = Entity.find(:all) 12 13 respond_to do |format| 14 format.html # index.html.erb 15 format.xml { render :xml => @entities } 16 end 17 end
When I look at views/entities/index I get this error:
uninitialized constant Location::Sites
... 64: <% if entity.locations.empty? -%> 65: <%= link_to 'Add Locations', new_entity_locations_path(entity) -%> 66: <% else -%>
... app/controllers/entities_controller.rb:13:in `index'
I am evidently overlooking something obvious but for the life of me I cannot see what. Another pair of eyes is most welcome.