title: Dynamically add a form_tag using jQuery in Rails 3.2
body: <p>My app has a user dashboard that lists rules a user has created.  Each rule can be added to a "ruleset".  For each rule, I want to display a button that when clicked, loads a form that allows the user to add that rule to a ruleset. </p>
  
  <p>I have the following code in my view to show each rule:</p>
  
  <pre><code>&lt;% @rules.each do |rule| %&gt;
    &lt;div class="rule-wrapper"&gt;
  
      &lt;div class="rule-content row"&gt;
        &lt;div class="span6"&gt;
          &lt;strong&gt;Rule:&lt;/strong&gt; &lt;%= rule.description %&gt;
        &lt;/div&gt;
        &lt;div class="span2"&gt;           
          &lt;div class="add-to-ruleset-form"&gt;
  
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
    ......
  </code></pre>
  
  <p>The pertinent part of my Rules controller is as follows:</p>
  
  <pre><code>class RulesController &lt; ApplicationController
    before_filter :authenticate_user!
  
    def add_rule_to_ruleset
      @ruleset = Ruleset.find(params[:ruleset_id])
      @rule = Rule.find(params[:rule_id])
  
      @ruleset.rule &lt;&lt; @rule
  
    end
  
    ....
  </code></pre>
  
  <p>Lastly, here is what my dashboard.js.erb file looks like:</p>
  
  <pre><code>$('.add-to-ruleset').click(function(e){
    e.preventDefault();
    $('.add-to-ruleset-form').html('&lt;%= escape_javascript(link_to render :partial =&gt;   "add_to_ruleset_form", :locals =&gt; {:rule =&gt; rule}) %&gt;')
  });
  </code></pre>
  
  <p>I'd like that when a button ('add-to-ruleset') is clicked, that the partial is rendered.  I've tried using "escape_javascript" helper in my js.erb file but it isn't passing the "rule" variable corrent.  I've also tried to use jQuery's load(), but I don't know how to pass the "rule" instance variable to the partial using jQuery.  Is there another way?</p>