title: How to pass an argument into a controller method from a form_tag
body: <p>In my User Show view:</p>
  
  <pre><code>&lt;%= form_tag assign_as_student_path do %&gt;
      &lt;%= hidden_field_tag :user_id, @user.id %&gt;
      &lt;%= submit_tag "Assign as a Student", data: { confirm: "Are you sure?" } %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>TeachersController (inherits from UsersController):</p>
  
  <pre><code>def assign_as_student
      @user = User.find(params[:user_id])
      @user.update_attributes(type: "Student")
      @user.save
      redirect_to admin_path, notice: "They are now a Student" 
  end
  </code></pre>
  
  <p>routes.rb:</p>
  
  <pre><code>post 'assign_as_student' =&gt; 'teachers#assign_as_student'
  </code></pre>
  
  <p>Ok, this WORKS. But...</p>
  
  <p>This was what I had to settle for, because I didn't know how to pass an argument into the controller method.</p>
  
  <p>I wanted to write a method in the UsersController like the above one but with an argument like this (I think this would work, but haven't been able to test it):</p>
  
  <pre><code>def assign_as_type(type)
      @user = User.find(params[:user_id])
      @user.update_attributes(type: type)
      @user.save
      redirect_to admin_path, notice: "They are now a Student" 
  end
  </code></pre>
  
  <p>This way, I would be able to just have this one method instead of having an "assign_as_student" method AND an "assign_as_teacher" method. Always good to be DRY.</p>
  
  <p>So... I think the above method would work, but how would I pass the argument in from the form? Like the below form, but with something added that would pass in a string "Student" or "Teacher":</p>
  
  <pre><code>&lt;%= form_tag assign_as_type_path do %&gt;
    &lt;%= hidden_field_tag :user_id, @user.id %&gt;
    &lt;%= submit_tag "Assign as a (Student/Teacher), data: { confirm: "Are you sure?" } %&gt;
  &lt;% end %&gt;
  </code></pre>