Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Client</strong></p> <p>According to the <a href="http://api.jquery.com/jQuery.get/" rel="nofollow">$.get</a> and <a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow">$.ajax</a> docs, <code>params</code> will go into the query string part of the URL:</p> <pre><code>// request to /somethings?a=abc&amp;b=2 $.get('/somethings', {a: 'abc', b: 2}) </code></pre> <p><strong>Server</strong></p> <p>Query string parameters can be accessed from Rails actions via a Hash-like object called <code>params</code>. <a href="http://guides.rubyonrails.org/action_controller_overview.html#parameters" rel="nofollow">[1]</a></p> <pre><code>class SomethingsController &lt; ApplicationController def index puts params[:a] # if URL was /somethings?a=123, will print 123 end end </code></pre> <p><strong>Putting it Together</strong></p> <p>Let's make a complete example with a partial.</p> <p>Here is the client code:</p> <pre><code>// client call to /somethings?name=Something+123 $.get('/somethings', {name: 'Something 123'}, function(data){ $('#target').html(data); }); </code></pre> <p>Here is the server:</p> <pre><code>class SomethingsController &lt; ApplicationController def index # bind controller variable @name @name = params[:name] end end </code></pre> <p>Inside the view <code>app/views/somethings/index.html.erb</code>:</p> <pre><code>&lt;%= render :partial =&gt; 'some_partial', :locals =&gt; {:name =&gt; @name} %&gt; </code></pre> <p>I've moved the partial rendering into a view. I think rendering partials from views is more standard than rendering partials directly from controllers. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload