Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Rails 4 App-JS在开发模式下与Webrick合作,但与Passenger/Apache2合作_Javascript_Ruby On Rails_Apache_Coffeescript_Passenger - Fatal编程技术网

Javascript Rails 4 App-JS在开发模式下与Webrick合作,但与Passenger/Apache2合作

Javascript Rails 4 App-JS在开发模式下与Webrick合作,但与Passenger/Apache2合作,javascript,ruby-on-rails,apache,coffeescript,passenger,Javascript,Ruby On Rails,Apache,Coffeescript,Passenger,表单首先使用js根据选择的类别填充产品选择列表。这很有效。然后,它应该根据在产品选择框中选择的产品切换不同的div coffeescript文件的第一部分工作正常。如果我与Webrick一起提供页面,而不是通过Apache2/Passenger,则第二部分可以工作。我在日志文件中没有发现错误,IE调试器中也没有(是的,对)-DIV就是不显示 有人知道为什么文件的一部分总是工作,而另一部分只在某些时候工作吗 我认为这可能是一个资产管道问题,但是这两个函数都不起作用,对吗?我在开发模式下运行这个。提

表单首先使用js根据选择的类别填充产品选择列表。这很有效。然后,它应该根据在产品选择框中选择的产品切换不同的div

coffeescript文件的第一部分工作正常。如果我与Webrick一起提供页面,而不是通过Apache2/Passenger,则第二部分可以工作。我在日志文件中没有发现错误,IE调试器中也没有(是的,对)-DIV就是不显示

有人知道为什么文件的一部分总是工作,而另一部分只在某些时候工作吗

我认为这可能是一个资产管道问题,但是这两个函数都不起作用,对吗?我在开发模式下运行这个。提前感谢您的帮助

\u form.html.erb

    <%= form_for(@request) do |f| %>
      <% if @request.errors.any? %>
        <div id="error_explanation">
          <h2><%= pluralize(@request.errors.count, "error") %> prohibited this request from being saved:</h2>
          <ul>
          <% @request.errors.full_messages.each do |msg| %>
            <li><%= msg %></li>
          <% end %>
          </ul>
        </div>
      <% end %>
      <% if current_user %>
        <% if current_user.analyst %>   
          <div class="field">
            <font color="maroon">Check here for an IT Project-Related Request that has already been budgeted and does not require further departmental approvals :</font>   <%= f.check_box :project %>
          </div>
       <% end %>
      <% end %>   
      <p></p>

      <!-- SHOW ONLY CATEGORIES WITH ACTIVE PRODUCTS -->
      <div class="field" id="category">
        <%= f.label :category_id, "Select a Category:" %>
        <%= f.collection_select(:category_id, Category.sorted, :id, :name, :include_blank => true ) %>
      </div>

      <!--  BASED ON CATEGORY SELECTED ABOVE, LOAD CORRESPONDING ACTIVE PRODUCTS BELOW -->
        <div class="field" id="product">
        <%= f.label :product_id, "Select a Product/Service:" %>
        <%= f.grouped_collection_select :product_id, Category.active.sorted, :active_products, :name, :id, :name, include_blank: true %>
      </div>

      <!--  BASED ON PRODUCT SELECTED ABOVE, SHOW CORRESPONDING PRODUCT.DESCRIPTION AND CORRESPONDING DIV BELOW IF APPLICABLE -->

      <div class="field" id="product_description"> 
      <!-- <%#= @request.product.description %> ..... show the product.description of the product selected above -->
      </div>

      <div class="field" id="quantity">
        <%= f.label :quantity, "Quantity:" %>
        <%= f.text_field :quantity %>
      </div>

      <p></p>

      <div id="dynamic_portion">
                <!--<-- These are the custom DIVS that need to load based on the product_id selected above:-->

      </div>



      <!--  ALWAYS SHOW TEXT AREA FOR FURTHER INFO -->

        <div class="field" id="requestor_note">
            <%= f.label :requestor_note, "Please give full details below..." %>
            <%= f.text_area :requestor_note, :size => "50x6" %>
        </div>

        </br><p></p>
      <div>
        <%= f.submit "Submit", :name => nil, :class => "btn" %>
      </div>
    <% end %>
requests.js.coffee

jQuery ->

#//this handles product population based on category select - this works with Webrick and Phusion/Apache2

    $('#request_product_id').parent().hide()
    products = $('#request_product_id').html()
    emptyOption = $('<option />').attr('value', '');
    $('#request_category_id').change ->
        category = $('#request_category_id :selected').text()
        options = $(products).filter("optgroup[label='#{category}']").prepend(emptyOption).html()
        if options
            $('#request_product_id').html(options)
            $('#request_product_id').parent().show()
        else
            $('#request_product_id').empty()
            $('#request_product_id').parent().hide()


#// this should handle <div> toggle based on product select - this works with Webrick, but not Phusion Passenger/Apache2:

$("#request_product_id").change ->
  trial = $("#request_product_id option:selected").val()
  container = $("#dynamic_portion")
  $.ajax
    url: "/refresh_content?product_id=" + trial
    type: "get"
    dataType: "html"
    processData: false
    success: (data) ->
      container.html data
在Webrick中运行时,我得到以下信息:

Request URL:
    http://server/refresh_content?product_id=10

    Request Method:
    GET

    Status Code:
    HTTP/1.1 404 Not Found
Request URL:
    http://localhost:3000/refresh_content?product_id=10

      Request Method:
      GET

    Status Code:
    HTTP/1.1 200 OK 

运行apache时,它是从服务器根目录而不是应用程序根目录提供服务-??

我将ajax url更改为:

url: "/refresh_content?product_id=" + trial
致:

现在它开始工作了。谢谢你,萤火虫

url: "/refresh_content?product_id=" + trial
url: "/requests/refresh_content?product_id=" + trial