title: Rails Validation Issue on Form Submission
body: <p>I have two rails models associated with each other: students and courses. Multiple students can take multiple courses, so I decided to use a has_many_through association... as you can see below.</p>
  
  <p>I also added an index to make sure a student does not enroll for a course twice. However, whe I try to enroll it doesn't go through.</p>
  
  <p>student_enrollments:</p>
  
  <pre><code>    belongs_to :students
      belongs_to :courses
  
      validates :matriculation_number, presence: :true
      validates :course_code, presence: :true
  </code></pre>
  
  <p>student_enrollment schema</p>
  
  <pre><code> create_table "student_enrollments", id: false, force: :cascade do |t|
      t.string "course_code", null: false
      t.datetime "created_at", precision: 6, null: false
      t.datetime "updated_at", precision: 6, null: false
      t.string "matriculation_number"
      t.index ["course_code"], name: "index_student_enrollments_on_student_id_and_course_code", unique: true
    end
  </code></pre>
  
  <p>student_enrollments_controller:</p>
  
  <pre><code>class StudentEnrollmentsController &lt; ApplicationController
      before_action :authenticate_student!
  
      def new
          @courses = Course.all
          @course = []
          i = 0
          while i &lt; @courses.length
              @course.push(@courses[i].course_code)
              i += 1
          end
          @enrollment = StudentEnrollment.new
      end
  
      def create
          @enrollment = StudentEnrollment.new(enrollment_params)
  
          if @enrollment.save
              flash[:success] = "enrollment successful."
              redirect_to new_student_enrollment_path
          else
              flash[:danger] = "Enrollment failed."
              redirect_to new_student_enrollment_path
          end
      end
  
      private
  
          def enrollment_params
              params.require(:student_enrollment).permit(:course_code, :matriculation_number)
          end
  end
  </code></pre>
  
  <p>student</p>
  
  <pre><code>    has_many :student_enrollments
      has_many :courses, through: :student_enrollments
  </code></pre>
  
  <p>course</p>
  
  <pre><code>    has_many :student_enrollments
      has_many :students, through: :student_enrollments
  </code></pre>
  
  <p>I also added an index to make sure a student does not enroll for a course twice. However, whe I try to enroll it doesn't go through. The output when I try to create the entry via the console: <code>ActiveRecord::RecordInvalid (Validation failed: Students must exist, Courses must exist)</code>.</p>