title: How to access my instance variable in my partial
body: <p>I'm having trouble accessing my instance variable. My code is as follows:</p>
  
  <pre><code># controllers/locations_controller.rb
  def index
    if request.xhr?
      neLat = data.dig('northeast', 'lat').to_f
      neLng = data.dig('northeast', 'lng').to_f
      swLat = data.dig('southwest', 'lat').to_f
      swLng = data.dig('southwest', 'lng').to_f
  
      @markers = Location
        .where("lat &lt;= ?", neLat)
        .where("lng &lt;= ?", neLng)
        .where("lat &gt;= ?", swLat)
        .where("lng &gt;= ?", swLng)
    end
  
    respond_to do |format|
      format.html
      format.json {render :json =&gt; @markers}
      format.js
    end
  end
  
  
  # view/locations/_map.html.erb
  $.ajax({
    url: '/location.json',
    type: 'GET',
    contentType: "application/json; charset=utf-8",
    data: {
      "northeast": bounds.getNorthEast().toJSON(),
      "southwest": bounds.getSouthWest().toJSON(),
    }
  })
  .done(function(data) {
    // EDIT HERE
    console.log(data)
    console.log(&lt;%= @markers %&gt;)
    // END OF EDIT
    $('.results').html("&lt;%= j render 'locations/location_results' %&gt;")
  });
  </code></pre>
  
  <p>When I console.log(data) after my ajax has successfully completed I'm getting my anticipated results, however when I console.log(&lt;%= @markers %>) I'm getting empty results.  How do I get access to my instance variable?\</p>
  
  <p>EDIT:</p>
  
  <p>So I ended up passing a hash from my controller to my view like this:</p>
  
  <pre><code># controller
  renderPartial = render_to_string :partial =&gt; 'locations/location_results.html.erb'
  respond_to do |format|
    format.html        
    format.json {render :json =&gt; {markers: @markers, partial: renderPartial}}
  end
  
  # view
  .done(function(data) {
    if (data) {
      $('.results').html(data.partial)
      return addMarkers(data.props)
    }
  })
  </code></pre>
  
  <p>This let me render my partial and have access to my instance variable with erb and also use the callback variable in javascript.</p>