title: Ruby on rails adding users to groups
body: <p>I am building a social networking site with user, school, and schoolgroup models.  The users join, and have different roles in, the schools through the has_many through schoolgroups.  I am having trouble writing an online form_for button that a user can click on to apply to the school.  The params I need to be included in the creation of the schoolgroup object are the user_id, the school_id, and the role 'applicant'.  I know that I can use current_user.schoolgroups.build to have the form initialize a create action and include the correct user_id, but the problem I am having is how to write a form which sends the school_id to the controller to create the new schoolgroup object.  The @school instance variables in my code are just placeholders for whatever the correct code should be </p>
  
  <pre><code>def create
    @school = School.find(params[:schoolgroups][:school_id)
    current_user.schoolgroups.build(school_id: @school.id, user_id: current_user.id, role: 'applicant')
    respond_with school_path
   end
  
  &lt;%= form_for( current_user.schoolgroups.build(params[school_id: @school.id]), 
                                                         remote: true) do |f| %&gt;
    &lt;div&gt;&lt;%= f.hidden_field :school_id %&gt;&lt;/div&gt;
     &lt;%= f.submit "Apply", class: "btn btn-large btn-primary" %&gt;
     &lt;% end %&gt;
  </code></pre>