私の検証で私の関連で生成されたメソッドを呼び出す際に問題があります。関連付けメソッドを検証から呼び出すことができません
私のコードは非常に単純です:
class Match < ActiveRecord::Base
# Associations
belongs_to :tournament
has_many :match_player_relations
has_many :waiting_players, through: :match_player_relations
has_many :replays
# Validations
validates :tournament_id, presence: true
validates :winner_id, inclusion: { in: waiting_players.map { |wp| wp.id } }
end
私はwaiting_players方法があることを私のテストで検証している、それが正常に動作します。しかし、私の検証でそれを呼び出そうとすると、次のエラーが発生します。
/Users/max/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/base.rb:1088:in `method_missing': undefined local variable or method `waiting_players' for #<Class:0x007fc3b498c9c8> (NameError)
from /Users/max/workplace/CloudLeagues/app/models/match.rb:11:in `<class:Match>'
これを解決する方法はありますか?または、検証を削除する必要がありますか?
をそれがself.waiting_players' 'で動作しますか? – Baldrick
いいえ、私は同じエラーが発生します。 – Max
この質問を見るのは不可能かもしれません:http://stackoverflow.com/questions/5034988/rails-3-validates-inclusion-of-when-using-a-find-how-to-proc-or-ラムダ – Baldrick