title: how to validate associated model id?
body: <p>I have a student and a course model. Student belongs to course, and course has many students.</p>
  
  <pre><code>class Student &lt; ActiveRecord::Base
    attr_accessible :course_id, :name, :password, :status, :studentID, :year
    belongs_to :course
  
    validates :name, :password, :status, :studentID, :year, :presence =&gt;true
    validates_associated :course
  end
  
  class Course &lt; ActiveRecord::Base
    attr_accessible :courseCode, :courseName, :courseYr
    validates :courseCode,:courseName,:courseYr, :presence =&gt; true
    validates :courseCode,:courseYr, :uniqueness=&gt;{:message=&gt;"Cannot repeat the code"}
  
    has_many :students 
  end
  </code></pre>
  
  <p>In the form used to create student record, I let the user enter the course ID.</p>
  
  <pre><code>&lt;div class="field"&gt;
    &lt;%= f.label :course_id %&gt;&lt;br /&gt;
    &lt;%= f.text_field :course_id %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>But I don't know how to validate the <code>course_id</code> input by the user. The student model validation will not generate an error, even when I type a course ID that does not exist. How do I get it to show the error?</p>