我有以下代码这给我一个ActionView::Template::Error (undefined method
roster_path”为#<#:0x007fe34005c208>):`删除HABTM对象
虽然在后台它删除关联player_roster(有和属于多个),但是当我按下链接时我想删除它。
名册的路径嵌套在一个团队内,但问题是关于名册和球员。
<%= form_for [@team, @roster] do |f| %>
<% @players.each do |player| %>
<%= player.gamertag %>
<%= link_to "Delete", player.rosters.delete(@roster) %>
<% end %>
<% end %>
:更新
Player.rb
class Player < ActiveRecord::Base
has_and_belongs_to_many :rosters
belongs_to :country
mount_uploader :picture, PictureUploader
end
Roster.rb
class Roster < ActiveRecord::Base
has_and_belongs_to_many :players
has_many :placements
belongs_to :team, touch: true
end
你有什么关系,就像在你的模型?删除发生的方式是使用'dependent::destroy',但除非你发布了模型代码,否则我们不知道:) –
用两种模型更新我的问题:) – Pierre