我正在尝试制作一种搜索功能,该功能将获取所有与特定members
关联的 current_usersgame
id
我试过了:
@members = current_user.members.where(:games.id => params[:id])
但我得到:
undefined method `id' for :games:Symbol
这将如何在 Rails 中完成?
更新: 模型关联
class Member < ActiveRecord::Base
has_many :games_members, :dependent => :destroy
has_many :games, :through => :games_members, :uniq => true
end
class GamesMembers < ActiveRecord::Base
self.primary_key [:game_id, :member_id]
belongs_to :members
belongs_to :games
end
class Game < ActiveRecord::Base
has_many :games_members, :dependent => :destroy
has_many :members, :through => :games_members, :uniq => true
end