title: How to load instance variable on ajax success request after page load in rails?
body: <p>I have a method in api that returns json object of vehicles. </p>
  
  <pre><code>class TestApi
   def test_method
    @vehicle = Vehicle.where(owner_id: current_user.id)
    respond_to do |format|
     format.json { render json: @vehicle }
    end
   end
  end
  </code></pre>
  
  <p>I have a view page from where I do the get request to test_method to get the @vehicle object. How can I keep changing @vehicle object using ajax on success and populate in my view so that on different user view I get the dynamic @vehicle object?</p>
  
  <pre><code>.container
    - @vehicle.each do |v|
     %p v.name
  
  :js
    $(window).on('load', function() {
      $.ajax({
        url: "/api/v1/vehicle/test_method" + rv_id,
        success: function(result){
          console.log('Got the result', html);
        }
      })
    })
  </code></pre>