title: How to update attributes in many to many relation in rails?
body: <p>I am new in rails. So i am not comprehending much of it. I have a database with three table. students table, courses table and registrations table.
  My Railde models are as follows :</p>
  
  <pre><code>class Student &lt; ActiveRecord::Base
    attr_accessible :name
    has_many :registrations
    has_many :courses, :through =&gt; :registrations
  
    validates :name, :presence =&gt; true
  
  end
  
  class Course &lt; ActiveRecord::Base
    attr_accessible :name
    has_many :registrations, :dependent =&gt; :destroy
    has_many :students, :through =&gt; :registrations
  
    validates :name , :presence =&gt; true
    validates :name, :uniqueness =&gt; true
  end
  
  class Registration &lt; ActiveRecord::Base
    attr_accessible :course_id, :student_id
  
  
    belongs_to :course
    belongs_to :student
  
    validates :course_id, :student_id, :presence =&gt; true
    validates :course_id, :uniqueness =&gt; {:scope =&gt; :student_id}
    validates :student_id, :uniqueness =&gt; {:scope =&gt; :course_id}
  end
  </code></pre>
  
  <p>......................</p>
  
  <pre><code>Controller action for updating student :
  
    def update
      @student = Student.find(params[:id])
      if @student.update_attributes(params[:student])
        redirect_to students_path, :notice =&gt; "Registration completed"
      else
        render 'edit'
      end
    end
  </code></pre>
  
  <p>................
  View :</p>
  
  <pre><code>&lt;%=form_for @student do |f| %&gt;
      &lt;p&gt;
        &lt;%= f.label :name, "Name" %&gt;
        &lt;%= f.text_field :name %&gt;
      &lt;/p&gt;
      &lt;p&gt;
        &lt;%= render('course_list') %&gt;
      &lt;/p&gt;
      &lt;p&gt;
        &lt;%= f.submit %&gt;
      &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>...............
  _course_list partial :</p>
  
  <pre><code>Select Courses :&lt;br/&gt;
  
          &lt;p&gt;
  
            &lt;% Course.all.each do |course| %&gt;
  
                &lt;%=check_box_tag "student[course_ids][]", course.id, `enter code here`@student.course_ids.include?(course.id) %&gt;
                &lt;%= course.name %&gt;  &lt;br/&gt;
  
            &lt;% end %&gt;
      &lt;/p&gt;
  </code></pre>
  
  <p>.............................
  when i submit the update button, i got an error </p>
  
  <p>Can't mass-assign protected attributes: course_ids</p>
  
  <p>.......</p>
  
  <p>parameters :</p>
  
  <pre><code>{"utf8"=&gt;"✓",
   "_method"=&gt;"put",
   "authenticity_token"=&gt;"j/lDE5bv1gWkfadQ6Cag6hGjg5nD2Ikad9vHOJTE7Pc=",
   "student"=&gt;{"name"=&gt;"Galib",
   "course_ids"=&gt;["2",
   "3"]},
   "commit"=&gt;"Update Student",
   "id"=&gt;"6"} 
  </code></pre>
  
  <p>......................... </p>
  
  <p>What i want to do is, if update button is clicked, both students table and registrations table need to be updated.  Please help.</p>