title: How to pass parameter to js.erb in Rails?
body: <p>I want to an ajax request to call <code>user</code> controller's <code>xyz</code> action with the passed parameter <code>stage</code> and then append it on <code>#the_box</code> so that I can perform conditional operation like for stage <code>x</code> append <code>@user.age</code>, for stage <code>y</code> append <code>@user.age+1</code> and for stage <code>z</code> append <code>@user.age-1</code>. How should I do?</p>
  
  <p>I have a html.erb file contains such code:</p>
  
  <pre><code>&lt;center&gt;
    &lt;%= link_to "A", xyz_user_path, stage: "x", remote: true %&gt;
    &lt;%= link_to "B", xyz_user_path, stage: "y", remote: true %&gt;
    &lt;%= link_to "C", xyz_user_path, stage: "z", remote: true %&gt;
  &lt;/center&gt;
  &lt;div id="the_box"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>and <code>users_controller.rb</code> has</p>
  
  <pre><code>before_action :set_user, only: [ :xyz]
  
  def xyz
      respond_to do |format|
          format.js {}
      end
  end
  
  private
  def set_user
      @user = User.find(params[:id])
  end
  </code></pre>
  
  <p>and this <code>xyz.js.erb</code> is what I have now but cannot deal with parameter so it cannot handle conditional operation</p>
  
  <pre><code>$("#the_box").append("&lt;%= @user.age%&gt;");
  </code></pre>