title: How to pass parameters with form_for to controller ruby on rails
body: <p>I have a user model and a course model, and user can upload courses for themselves after they login.</p>
  
  <p>However, I want admin to be able to upload for users to in case the user is not savvy enough.</p>
  
  <p>My thought was to use the same create action for both user-upload and admin-upload, with an if statement. </p>
  
  <p>The admin will select the user before he uploads for him in users/:id view page:</p>
  
  <pre><code>&lt;%= link_to 'Upload Course for User', new_course_path(user_id: params[:id]), class: 'btn btn-primary' %&gt;
  </code></pre>
  
  <p>Then I was able to see the create page with the parameter:</p>
  
  <p><a href="http://localhost:3000/courses/new?user_id=10" rel="nofollow">http://localhost:3000/courses/new?user_id=10</a></p>
  
  <p>and I submit this form</p>
  
  <pre><code>&lt;%= form_for(@course, html: {class: "form-group"}) do |f| %&gt;
  ...
  &lt;%= f.submit "Create Course", class: 'btn btn-primary' %&gt;
  </code></pre>
  
  <p>to the create action in the controller:</p>
  
  <pre><code>def create
    @course = Course.new(course_params)
    @course.user_id = params[:user_id] || current_user.id
    if @course.save
      redirect_to course_path(@course), notice: 'The course has been created successfully!'
    else
    render 'new'
  end
  </code></pre>
  
  <p>However I'm never getting the user_id params, always just the current_user.id, which is the admin_user's id and that's not good.</p>
  
  <p>How do I manage to pass in the user_id parameter to the controller create action so that it knows I'm trying to create for another user, not myself? Is there a better way to handle this than my logic?</p>
  
  <p>Thanks!</p>