title: Rails 4: Rendering JSON object (from AJAX response) into view
body: <p>I'm using Rails 4 and I'm quite new to JSON objects.</p>
  
  <p>I have a controller:</p>
  
  <pre><code>class UsersController &lt; ApplicationController
  
   def select_users
  
     @users = User.all
     respond_to do |format|
       format.html
       format.js {} 
       format.json { 
          render json: {:users =&gt; @users}
       } 
     end
   end
  end
  </code></pre>
  
  <p>And a javascript users.js: </p>
  
  <pre><code>$.ajax({
      url:  "/users/select_users",
      dataType: "json",
      data: {
          prezzario: ui.item.value
      },
      success: function(data) { 
          $('#usersList').append(data.users);
      }
  });
  </code></pre>
  
  <p>Now I want to render this collection of users in a div, but I don't know how. In the data response I have in the console the correct data, with an object like this:</p>
  
  <pre><code>{"users":[{"_id":{"$oid":"536cf7b6b8dd181f4b7acf9f"},"children":[{"$oid":"536cf7b6b8dd181f4b7acfa0"},{"$oid":"536cf7b7b8dd181f4b7acfd1"}],"description":"Some description.","name":"My name","user_id":"1"},{...........}]}
  </code></pre>
  
  <p>I have a partial /users/_users.html.erb with classic users.each and prints of all properties.
  If I try</p>
  
  <pre><code>$('#usersList').append("&lt;%= render 'users', :locals{ :users =&gt; "+data.users+"} %&gt;");
  </code></pre>
  
  <p>I find in the div <code>#usersList  &lt;%= render 'users', :locals{ :users =&gt; undefined }%&gt;</code></p>
  
  <p>I want to create a partial template and use it to render users. How can I do this?</p>