简体   繁体   English

Rails 4 App-JS在开发模式下可与Webrick一起使用,但不适用于Passenger / Apache2

[英]Rails 4 App - JS works with Webrick but not Passenger/Apache2 in Development Mode

The form first uses js to populate a product select list based on selecting a category. 该表单首先使用js根据选择类别填充产品选择列表。 This works. 这可行。 Then it should toggle different divs based on which product is selected in the product select box. 然后,应根据在产品选择框中选择的产品来切换不同的div。

The first part of the coffeescript file works fine. coffeescript文件的第一部分工作正常。 The second part works if I serve the page with Webrick, but not via Apache2/Passenger. 如果我使用Webrick为页面提供服务,而不是通过Apache2 / Passenger服务,则第二部分可以工作。 I get no errors in the log files, nor in the IE debugger (yeah, right) - the divs just don't show up. 我在日志文件或IE调试器中都没有错误(是的,是的)-div不会显示。

Does anyone know why part of the file works all of the time and the other part only works some of the time? 有谁知道为什么文件的一部分始终有效,而另一部分却始终有效?

I thought it might be an asset pipeline issue, but then neither of the functions would work, right? 我以为这可能是资产流水线问题,但随后两个功能都不起作用,对吧? I am running this in DEVELOPMENT mode. 我正在开发模式下运行它。 Thanks in advance for any help. 在此先感谢您的帮助。

_form.html.erb _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_controller.rb: requests_controller.rb:

      def refresh_dynamic_content
        @product = Product.find(params[:product_id])
        if @product.id == 8
          render :partial => 'requests/new_city_employee' ,:layout => false
        elsif @product.id == 10
          render :partial => 'requests/exit_employee' ,:layout => false
        elsif @product.id == 12 or @product.id == 21
          render :partial => 'requests/change_employee' ,:layout => false
        end
      end

requests.js.coffee request.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

Update - Firebug: 更新-Firebug:

When running with Apache/Passenger, I get this: 使用Apache / Passenger运行时,得到以下信息:

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

    Request Method:
    GET

    Status Code:
    HTTP/1.1 404 Not Found

When running in Webrick, I get this: 在Webrick中运行时,我得到以下信息:

Request URL:
    http://localhost:3000/refresh_content?product_id=10

      Request Method:
      GET

    Status Code:
    HTTP/1.1 200 OK 

When running apache, it is serving from the server root, not the application root - ?? 当运行apache时,它是从服务器根目录而不是应用程序根目录提供服务的?

I changed the ajax url from: 我从以下位置更改了ajax网址:

url: "/refresh_content?product_id=" + trial

to: 至:

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

And now it works. 现在就可以了。 Thank you, Firebug. 谢谢你,萤火虫。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular / JS Express应用程序在生产模式下处于无限路由循环中,在开发模式下运行良好 - Angular/JS Express app in infinite routing loop in production mode, works fine in development mode React.js 应用程序在开发模式下运行良好,但在构建(生产模式)后出现错误 - React.js app works fine in development mode but has errors after building (production mode) 是否可能以及如何在此环境中部署Node + Passenger应用程序(HAProxy 1.4-&gt; Apache2) - Is it possible and if, how to deploy Node + Passenger app in this environment (HAProxy 1.4->Apache2) CSS / JS addClass可在开发中使用(Rails),但不能在heroku中使用 - CSS/JS addClass works in development (Rails) but not in heroku webrick服务器/ ie6在开发模式下截断javascript文件 - webrick server / ie6 truncating javascript files in development mode JavaScript缓存,Rails和Apache乘客? - JavaScript caching, Rails and Apache passenger? 代理错误502,在apache2服务器上运行Node js应用 - Proxy error 502 , run node js app on apache2 server Vue.js Vite 应用程序在开发中工作,但在构建后崩溃 - Vue.js Vite app works in development but crashes after building 如何从 apache2 VPS 在子域上托管 Node.js 应用程序? - How do I host a Node.js app on a subdomain from an apache2 VPS? JS 文件无法在 apache2 上加载 - JS files doesn't load on apache2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM