I am having some difficulty conceiving how to best address a parameter passing problem I am having with rails. I am sure that this has been encountered and solved by others so perhaps someone can illuminate my ignorance.
I have the following models:
Entity has_many :locations has_many :site_locations, :include => :sites has_many :sites, :through => :site_locations
Site has_many :locations
Location belongs_to :entity belongs_to :site
Typically a site is created together with a location. The call from entities/index looks like this:
<% if entity.locations.empty? -%> <%= link_to 'Add Locations', new_entity_location_path(entity) -%> <% else -%>
which passes this params hash to the locations_controller action new:
entity_id: "3" action: new controller: locations
What I require is for the value {:entity_id => '3' } to be retained and passed back to the controller for the subsequent locations/show view. I tried doing this in the locations/new view:
<%= hidden_field_tag :entity_id, params[:entity_id].to_s -%>
but that did not work. How do I accomplish this?