title: Get + Set different instance variables in same controller
body: <p>I'm looking at a project online and stumbled across something that I don't understand. I have multiple <code>Users</code>, each User has <code>Comments</code>. Is it ok to do both <code>set_user</code> and <code>get_comment</code> inside of the <code>comment_controller</code>? The <code>button_to</code> tag ends up passing in user, but only <code>params[:user_id]</code> is usable.</p>
  
  <p><strong>users/index.html.erb</strong></p>
  
  <pre><code>&lt;h3&gt;All Users and Comments&lt;/h3&gt;
  &lt;%= render @users %&gt;
  </code></pre>
  
  <p><strong>users/_user.html.erb</strong></p>
  
  <pre><code>&lt;h4&gt;&lt;%= user.username %&gt;&lt;/h4&gt;
  &lt;%= render user.comments %&gt;
  
  &lt;%= button_to "Add comment to User", user_comments_path(user) %&gt;
  </code></pre>
  
  <p><strong>users_controller.rb</strong></p>
  
  <pre><code>class UsersController &lt; ApplicationController
  
    def index
      @users = User.order(:username)
    end
  
  end
  </code></pre>
  
  <p><strong>comments_controller.rb</strong></p>
  
  <pre><code>class CommentsController &lt; ApplicationController
  
    before_action :set_user
  
    def create
      @new_comment = @user.comments.create!(content: "Lorem Ipsum")
    end
  
    def update
      @comment.update_attributes(params.require(:comment).permit(:content))
    end
  
    private
  
      def set_user
        debugger
        @user = User.where(id: get_comment.user_id).first!
      end
  
      def get_comment
        @comment ||= Comment.where(id: params[:id]).first!
      end
  
  end
  </code></pre>
  
  <ol>
  <li>Wouldn't I want to just set the user using the given <code>user_id</code>, and then the <code>create</code> action would be creating the new Comment? That means I'd have to have 2 <code>before_action</code>'s right?</li>
  <li>This code works as is for the <code>update</code> action - it correctly gets <code>@user</code> and <code>@comment</code> because the comment exists. What would I need to do to make both <code>create</code> and <code>update</code> work?</li>
  </ol>