ユーザがopportunityをcreateする際、同じ内容で
別のユーザーからopportunityを受けていないかをチェックしたいです。createするユーザによってopportued_idとopportuer_idが変わります。
モデル
・カラム
opportunity
・user_id
・opportued_id
・opportuer_id
lang
1validate :cross_opportunity 2 def cross_opportunity 3 id = User.current_user.id 4 @opportunity = Opportunity.where(user_id: id) 5 errors.add(:base, 'xxxxx') if @opportunity.where(opportued_id:self.opportuer_id ,opportuer_id:self.opportued_id).count == 1 6 end
デバッグしたところuser_idはしっかりと取れていました。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/01/24 14:15
2015/01/24 14:25
2015/01/25 09:22
2015/01/25 15:19