我有問題的button_to路由到錯誤的控制器刪除。目標是調用分配控制器中的刪除方法並刪除關係,但不刪除聲明或位置。問題是它保持路由到位置控制器。Rails 3 - Button_to路由到錯誤的控制器方法(:刪除)
我有三個型號有HMT設置:
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
對這些索賠控制器我有以下語句獲取所有位置的要求。
@locations = @claim.locations.all
在理賠查看我有以下聲明
<% @locations.each do |location| %>
...
<td><%= button_to 'Remove', location , :method => :delete %></td>
<% end %>
所以,當我選擇按鈕,它調用位置控制器內刪除方法。 我需要將它設置爲在分配控制器中調用聲明和位置之間鏈接的刪除方法。
我試圖改變我如何獲取數據@locations = @ claim.locations.all也閱讀使用分配信息:包括,或:加入,但似乎沒有將其添加到返回的數據。
我試圖改變button_to調用作業,但我不知道如何。