title: Controller method using JS doesn't return/render data when called within modal popup
body: <p>I've been stuck with this problem a couple of days, and I didn't find anything that could help me.</p>
  
  <p>The idea is to get price_scenarios index view rendered in a modal popup. For each price_scenario shown in the table, a controller method, "price" is called. This method gets some info from the model and render it formated using JSON. This way of getting the prices was coded for a previous developer who is no longer in the project, and is necessary becouse price values can take a while to be calculated, so a small wheel gif is rendered when page loads. </p>
  
  <p>The problem: price_scenarios "price" method doesn't render any value. This only happens if "price" is called within the index view rendered in a modal popup, I've tried doing this rendering price_scenarios index and it works fine. Also, this method is succesfully used in many other views of the app. I think it must be a problem with format responses, due to call the method from a popup, but everything I've tried haven't improved the results.</p>
  
  <p><strong>product show.html.haml</strong> a button displaying price_scenarios index as a modal popup:</p>
  
  <pre><code> %h3
     = model_class.human_attribute_name(:price)
     = link_to PriceScenario.model_name.human(count: 2), formula_product_price_scenarios_path(@formula, @product), remote: true, data: {toggle: "modal", target: "#price_scenarios"}, class: "btn"
  
   #price_scenarios(class="modal hide fade" role="dialog" aria-labelledby="Delta" aria-hidden="true")
  </code></pre>
  
  <p><strong>price_scenarios_controller.rb</strong> definition of index and price methods</p>
  
  <pre><code>class PriceScenariosController &lt; ApplicationController
    before_filter :require_client
    load_and_authorize_resource :formula
    load_and_authorize_resource :product, :through =&gt; :formula
    before_filter :get_tuple, only: :price
  
    def index
      @price_scenarios = @product.price_scenarios
      respond_to :js
    end
  
    def price
      @price_scenario = PriceScenario.find(params[:id])
      @price = @price_scenario.shifted_price(@tuple)
      @price_units = @product.price_units
  
      respond_to do |format|
        format.html { render partial: 'price'}
        format.json { render json: {price: @price, units: @price_units}}
      end
    end
  </code></pre>
  
  <p><strong>price_scenario index.js.haml view</strong> renders index view in the modal:</p>
  
  <pre><code>$("#price_scenarios").html("#{escape_javascript(render partial: 'modal_price_scenarios')}");
  </code></pre>
  
  <p><strong>_modal_price_scenarios.html.haml</strong> view rendered in the modal, "price" is called within it.</p>
  
  <pre><code>#modal_price_scenarios(class="modal" role="dialog" aria-labelledby="Delta" aria-hidden="true")
  
    - model_class = PriceScenario
  
    .modal-body
      %table.table.table-striped
        %thead
          %tr
            %th= model_class.model_name.human
            %th= model_class.human_attribute_name(:price)
            %th= model_class.human_attribute_name(:references)
        %tbody
          - @price_scenarios.each do |scenario|
            %tr
              %td= scenario.name
              %td.price{:"data-product-price" =&gt; price_formula_product_price_scenario_path(@formula, @product, scenario)}
                = image_tag('ajax-loader.gif')
  </code></pre>
  
  <p><strong>-Price.html.haml partial</strong> rendered by price_scenarios price method.</p>
  
  <pre><code>= "#{@price} #{@price_units}"
  </code></pre>
  
  <p><strong>product_price.js</strong></p>
  
  <pre><code>$(function(){
    $('[data-product-price]').each(function(){
      var url = $(this).data('product-price')
      $.ajax({
        url:      url,
        cache:    false,
        dataType: "json"
      }).done(function( data ) {
          var priceWithUnits = data['price'] + ' ' + data['units']
          $('[data-product-price="' + url + '"]').html(priceWithUnits);
        });
    });
  });
  </code></pre>
  
  <p>Browser console and development log don't show any error, but it seems that proper requests are not being done. Launching a manual request via HttpRequester produces the right result.</p>
  
  <p><strong>Browser console</strong> after showing the modal:</p>
  
  <pre><code>GET localhost:3000/es/formulas/84/products/69/price_scenarios [HTTP/1.1 200 OK 1590ms] 
  POST http://localhost:3000/mini-profiler-resources/results [HTTP/1.1 200 OK 154ms]
  </code></pre>
  
  <p><strong>Development log</strong></p>
  
  <pre><code>Rendered price_scenarios/_modal_price_scenarios.html.haml (1537.1ms)
  Rendered price_scenarios/index.js.haml (1542.6ms)
  </code></pre>
  
  <p><strong>Manual request</strong></p>
  
  <pre><code>GET http://localhost:3000/es/formulas/84/products/69/price_scenarios/20/price?_=1427‌​711855278 -- response -- 200 OK 
  Content-Type: text/html; charset=utf-8 X-UA-Compatible: IE=Edge Cache-Control: must-revalidate, private, max-age=0 X-Request-Id: af912de9ef3e953387ddbd5f687aa1c2 X-Runtime: 2.647176 X-Miniprofiler-Ids: ["yxomxau7wdgouexw439j"] Content-Length: 18 Server: WEBrick/1.3.1 (Ruby/1.9.3/2014-02-24) Date: Mon, 30 Mar 2015 11:04:41 GMT Connection: Keep-Alive 275.391 EUR / MWh
  </code></pre>