フォームは最初に js を使用して、カテゴリの選択に基づいて製品選択リストを作成します。これは機能します。次に、製品選択ボックスで選択されている製品に基づいて、さまざまな div を切り替える必要があります。
coffeescript ファイルの最初の部分は問題なく動作します。2 番目の部分は、Apache2/Passenger 経由ではなく、Webrick でページを提供する場合に機能します。ログ ファイルにも IE デバッガーにもエラーは発生しません (そうです)。div が表示されないだけです。
ファイルの一部が常に機能し、他の部分が時々しか機能しない理由を誰かが知っていますか?
アセット パイプラインの問題かもしれないと思ったのですが、どちらの機能も機能しませんよね? これを DEVELOPMENT モードで実行しています。助けてくれてありがとう。
_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
requests.js.コーヒー
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/Passenger で実行すると、次のようになります。
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 を実行すると、アプリケーション ルートではなく、サーバー ルートから提供されます - ??