title: Passing Javascript variables to Rails partials
body: <p>I am new in Rails and I am struggling on an apparently easy task.
  I have a (stripped down) form:</p>
  
  <pre><code>&lt;%= form_for @order, html: { :class =&gt; 'form-inline' } do |f| %&gt;
    &lt;fieldset&gt;
    &lt;legend&gt;&lt;%= params[:action].capitalize %&gt; Order&lt;/legend&gt;
  
    &lt;table class="table"&gt;
      &lt;thead&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;%= f.label :symbol %&gt;&lt;/th&gt;
          &lt;th&gt;&lt;%= f.label :price %&gt;&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/thead&gt;
  
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;%= f.text_field :symbol, class: 'input-small' %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= f.text_field :price, class: 'input-small' %&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  
    &lt;div id='here'&gt;&lt;/div&gt;
  
    &lt;%= f.submit "Submit", class: "btn btn-primary" %&gt;
  
    &lt;/fieldset&gt;
  &lt;% end %&gt;
  
  &lt;%= link_to 'Get quote', view_quote_orders_path, remote: true %&gt;
  </code></pre>
  
  <p>I want to render the quotation in google finance in the div $(#here) when I click on 'Get quote' and when the symbol text field loses focus.
  I have already written the code to extract the quotation in Ruby.</p>
  
  <p>In routes.rb I added:</p>
  
  <pre><code>  resources :orders do
      get 'view_quote', on: :collection
    end
  </code></pre>
  
  <p>In order_controller.rb I added:</p>
  
  <pre><code>def view_quote
    respond_to do |format|
      format.js { render :layout =&gt; false }
    end
  end
  </code></pre>
  
  <p>and in view_quote.js.erb:</p>
  
  <pre><code>sym = $('.orders #order_symbol').val();
  $('#quotes').html("&lt;%=j render 'googlequote', symbol: sym %&gt;");
  </code></pre>
  
  <p>and in _googlequote.html.erb (where I will put the logic to extract the quotation):</p>
  
  <pre><code>&lt;%= symbol %&gt;
  </code></pre>
  
  <p>The error is in view_quote.js.erb, because sym is undefined.
  If I replace the second line with:</p>
  
  <pre><code>$('#quotes').html("&lt;%=j render 'googlequote', symbol: 'just_a_test' %&gt;");
  </code></pre>
  
  <p>the partial is rendered, but of course I don't need it.
  How can I pass the javascript variable sym to the partial _googlequote.html.erb?
  Otherwise, is there a better way to accomplish my objective?</p>