title: Injecting ruby with javascript on Ruby on Rails
body: <p>So, the thing that i want to do, is to have a button, to add more fields into a form. Let's say i have this:</p>
  
  <pre><code>&lt;div class="row"&gt;
        &lt;div class="form-group string required"&gt;
          &lt;div class="cep_filter"&gt;
            &lt;div class="col-md-3 traffic-columns"&gt;
              &lt;%= f.input :condition, collection: @traffic_columns, label: "Monitor (*)" %&gt;
            &lt;/div&gt;
            &lt;div class="col-md-1"&gt;
              &lt;%= f.input :operator, collection: @operator, label: "Op (*)" %&gt;
            &lt;/div&gt;
            &lt;div class="col-md-2"&gt;
              &lt;%= f.input :filter, label: "Value (*)",input_html: {type: "text" } %&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="col-md-3"&gt;
            &lt;%= f.input :window, collection: @window, label: "Window Type", input_html: {type: "text"} %&gt;
          &lt;/div&gt;
          &lt;div class="col-md-3"&gt;
            &lt;%= f.input :window2, label: "Window Value", input_html: {type: "text"} %&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Then, suppose i have a button like this:</p>
  
  <pre><code>&lt;%= link_to content_tag(:i, nil, class: "fa fa-plus"),
               '', style: 'color: green', class: "btn btn-small add-new-condition", 'data-backdrop' =&gt; "static" %&gt;
  </code></pre>
  
  <p>What i want to do, is that when you click that button, you call this:</p>
  
  <pre><code>$(document).on("click", ".add-new-condition", function(e) {
    var html =
    "&lt;div class='col-md-3 traffic-columns'&gt; \
      &lt;%= f.input :new_param, collection: @traffic_columns, label: 'Monitor (*)' %&gt;\
    &lt;/div&gt;
    "
  });
  </code></pre>
  
  <p>and then append that html to some div element. From what i've read, its not possible to inject ruby from javascript. Its something related to one being server side and the other client side. I already try it and the ruby code appears as a string. I could build those new fields by using the pure html, like  and so, but the important thing here, is that i want to add new fields that later i can access in a controller, for example the new field, with <code>params[:new_param]</code>. </p>
  
  <p>Is there a way to add new fields only with html so i can access later the entered value in my rails controller? Thank you.</p>