title: How do I validate uniqueness within a scope with a lambda function
body: <p>I'm trying to validate the uniqueness of a video_id relative to a session_id. I don't know what I'm doing wrong. Here's the model code that I have.</p>
  
  <pre><code>class SessionWatchHistory &lt; ActiveRecord::Base
    validates_presence_of :session_id, :on =&gt; :create, :message =&gt; "can't be blank"
    validates_presence_of :video_id, :on =&gt; :create, :message =&gt; "can't be blank"
  
    belongs_to :video, :class_name =&gt; "Video", :foreign_key =&gt; "video_id"
  
    scope :per_session, lambda{ |s| where("session_id = :session", :session =&gt; s)}
    validates_uniqueness_of :video_id, :scope =&gt; [:per_session]
  end
  </code></pre>