Rails 4 App-JS在开发模式下可以与Webrick合作,但不能与Passenger/Apache2合作
Rails 4 App - JS works with Webrick but not Passenger/Apache2 in Development Mode
表单首先使用js根据选择的类别填充产品选择列表。这是有效的。然后,它应该根据在产品选择框中选择的产品来切换不同的div。
coffeescript文件的第一部分运行良好。如果我使用Webrick提供页面,但不通过Apache2/Passenger,则第二部分有效。我在日志文件中没有错误,在IE调试器中也没有错误(是的,对)——div就是不显示。
有人知道为什么文件的一部分一直有效,而另一部分只在部分时间有效吗?
我认为这可能是一个资产管道问题,但这两个功能都不起作用,对吧?我在开发模式下运行这个。提前感谢您的帮助。
_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:
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
请求.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
更新-Firebug:
当使用Apache/Paxer运行时,我得到的是:
Request URL:
http://server/refresh_content?product_id=10
Request Method:
GET
Status Code:
HTTP/1.1 404 Not Found
当在Webrick中运行时,我得到的是:
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: "/requests/refresh_content?product_id=" + trial
现在它起作用了。谢谢你,萤火虫。
相关文章:
- 剑道UI不与流星合作
- ReactJS不与Zurb Foundation Accorsions合作吗
- 与杜兰达尔合作的第一个JavaScript项目.尝试从第三方 API 获取数据
- Jquery没有'不要与合作!文本插件需要带主干的js
- 如何使用Temasys AdapterJS与Microsoft Edge合作
- 合作伙伴网站托管的 Web 应用,而不公开源代码 - 可能
- 无法让Ajax与Angular合作
- JQuery不与Jade合作
- Meteor Accounts.ui.config 不与 Google 合作
- 合作页面之间的跨域、跨表通信
- Complexe child_process不与 Promise 蓝鸟合作
- 合作伙伴特定的JavaScript文件输出基于配置 /gruntjs
- RESTAdapter不与Ember合作
- Nodegit和Electron没有合作
- Pagedown和Angle Brackets不合作
- 要求JS、KendoUI和KnockoutJS有任何合作的机会
- Rails 4 App-JS在开发模式下可以与Webrick合作,但不能与Passenger/Apache2合作
- 将 removeChild 与 HTML 合作使用
- 如何创建“;场景”;与philips hue API合作
- 谷歌图表不与我合作