Note that there are some explanatory texts on larger screens.

plurals
  1. PORendering a ruby object through jQuery from a returned JSON object
    text
    copied!<p>I don't know if this is the right approach, but I want to do exactly what the title says. I'm missing some jQuery concepts, as I'm new to it.</p> <p>I am using jQuery.rest: <a href="https://github.com/lyconic/jquery.rest" rel="nofollow">https://github.com/lyconic/jquery.rest</a></p> <p>This script periodically checks to see if the online and offline users have been updated:</p> <pre><code>&lt;!-- Online checker --&gt; &lt;script type="text/javascript"&gt; $(function(){ setInterval (checkTrackings, 5000); var js = '&lt;checkTrackings&gt; '; function checkTrackings(){ $.read( '/users/{id}/check', { id: &lt;%= @user.id.to_json %&gt; }, function (response) { $("ul#online").empty(); $("ul#offline").empty(); // Code to add users back to list $("ul#online").html('&lt;%= escape_javascript(render(@online_users)).html_safe %&gt;') $("ul#offline").html('&lt;%= escape_javascript(render(@offline_users)).html_safe %&gt;') console.log(js + 'Check trackings'); } ); } }); &lt;/script&gt; </code></pre> <p>However, instead of @online_users and @offline_users, I need the returned JSON objects and need to convert them to said variables. The method that this script calls is here:</p> <pre><code> # Updates contacts def check @online_users = Array.new @offline_users = Array.new @user = User.find(params[:id]) @followed_users = @user.followed_users @followed_users.each do |followed_user| @online_users.push(followed_user) if followed_user.state.online end @offline_users = @followed_users - @online_users respond_to do |format| format.js { render :json =&gt; { :online_users =&gt; @online_users, :offline_users =&gt; @offline_users } } end end </code></pre> <p>Any other tips would be nice, too. I'm very new to web dev. Thanks for the help!</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