I have the following models
entity has_many :locations has_many :sites, :through => :locations
location belongs_to :entity belongs_to :site
site has_many :locations has_many :entities, :through => :locations
AND routes:
map.resources :entities do |entity| entity.resources :locations, :collection end
What I wish to do is to display all of the locations for a given entity. I have modified locations_controller to this:
# Limit locations list to just the parent entity before_filter :load_entity
# GET /locations # GET /locations.xml def index @locations = @entity.locations.find(:all) ... private
def load_entity @entity = Entity.find parms[:entity_id] end
And in views/entities/index.html.erb when I have this:
<td> <%= link_to 'Locations', entity_location_path -%> </td>
Then I get this:
entity_location_url failed to generate from {:controller=>"locations", :action=>"show"} - you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: ["entities", :entity_id, "locations", :id] - are they all satisfied?
If I have this in index.html.erb instead:
<td> <%= link_to 'Locations', entity_location_path(entity), :method => 'index' -%> </td>
Then I get this:
entity_location_url failed to generate from {:controller=>"locations", :entity_id=>#<Entity id: 1, entity_name: "my first client", entity_legal_name: "My First Client Ltd.", entity_legal_form: "CORP", created_at: "2008-03-25 22:41:43", updated_at: "2008-03-25 22:41:43">, :action=>"show"}, expected: {:controller=>"locations", :action=>"show"}, diff: {:entity_id=>#<Entity id: 1, entity_name: "my first client", entity_legal_name: "My First Client Ltd.", entity_legal_form: "CORP", created_at: "2008-03-25 22:41:43", updated_at: "2008-03-25 22:41:43">}
Which sends me back, as far as I can tell, to the first form of the call. Can someone straighten me out with respect to the proper link_to call to use?