I am having problems with the button_to routing to the wrong controller delete. The objective is to call the delete method in the assignment controller and delete the relationship, but not delete the Claim, or Location. The problem is that it keeps routing to the location controller.
I have three models with a HMT setup:
Claim
has_many :assignments
has_many :locations, :through => :assignments
Assignment
belongs_to :claim
belongs_to :location
Location
has_many :assignments
has_many :claims, :through => :assignments
Within the claims controller I have the following statement to get all of the location for a claim.
@locations = @claim.locations.all
Within a claims view I have the following statement
<% @locations.each do |location| %>
...
<td><%= button_to 'Remove', location , :method => :delete %></td>
<% end %>
So when I select the button it calls the delete method within the Locations controller. I need to set it up to call the delete method within the assignment controller which is the link between the claims and the Locations.
I have tried to change how I get the data @locations = @claim.locations.all to also read the assignment information using :include, or :join but nothing seems to add it to the data returned.
I have tried to change the button_to to call the assignment but I do not know how.