Note that there are some explanatory texts on larger screens.

plurals
  1. POrails render partial after ajax get request
    primarykey
    data
    text
    <p>I use Jvectormap into my Rails 3 app. When I click on it, I want to hide the map and visualize a partial with information about the selected country. </p> <p>I handle the map click and I send a GET req to the server.</p> <p>users.js.coffee.erb</p> <pre><code>$ -&gt; $("#world-map").vectorMap onRegionClick: (event, code) -&gt; $('#world-map').hide(1000) $.get('/users/statistics', {code: code}); $('#statistics').show(1000) </code></pre> <p>users_controller.rb</p> <pre><code>def statistics @country = Country.find_by_two_letter_code((params[:code]).downcase) render :nothing =&gt; true </code></pre> <p>end</p> <p>this is the response</p> <blockquote> <p>Started GET "/users/statistics?code=ET" for 127.0.0.1 at 2013-06-02 17:54:49 +0200</p> <p>Processing by UsersController#statistics as <em>/</em></p> <p>Parameters: {"code"=>"ET"}</p> <p>Country Load (0.2ms) SELECT "countries".* FROM "countries" WHERE </p> <p>"countries"."two_letter_code" = 'et' LIMIT 1</p> <p>Rendered text template (0.0ms)</p> <p>Completed 200 OK in 2ms (Views: 0.6ms | ActiveRecord: 0.2ms)</p> </blockquote> <p>and the view</p> <p>show.html.erb</p> <pre><code> &lt;p&gt; &lt;div id="world-map" style="width: 620px; height: 300px"&gt;&lt;/div&gt; &lt;div id="statistics" style="width: 620px; height: 300px; display:none;"&gt; &lt;section&gt; &lt;%= render partial:'statistics', :locals =&gt; {:country =&gt; @country} %&gt; &lt;/section&gt; &lt;/div&gt; &lt;/p&gt; </code></pre> <p>_statistics.html.erb</p> <pre><code>&lt;%= link_to '&lt;i class="icon-remove"&gt;&lt;/i&gt;'.html_safe%&gt; &lt;%=country%&gt; &lt;%=@country%&gt; </code></pre> <p>Now, everything works, but the partial doesn't visualize the country value. I don't undestand if I have to re-render the partial after the ajax get request, and how.</p> <p>I've tried to change the controller in another way, but the behavior is the same.</p> <pre><code>def statistics @country = Country.find_by_two_letter_code((params[:code]).downcase) render 'users/_statistics' end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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