0
## NO-AJAX, No filtering
# Since there is no filtering, it lists all the orders.
##
# partial:
<%= f.collection_select(:customer, @customers,
:customer_id, :customer_name, {:prompt=>'Select a Customer'})
%>
<%= f.collection_select(:order_id, @orders,
:order_id, :order_name, {:prompt=>'Select an Order'})
%>
# view:
<%= nested_form_for @service do |f| %>
<%= f.link_to_add "Add Order", :orders %>
<%= f.submit "Submit" %>
<% end %>
#controller:
def new
@service = Service.new
@service.orders.build
@customers = Customer.find(:all)
@orders = Order.find(:all)
end
## Q: BUT I WANT TO DO filtering based on the customer select, with AJAX and update the div accordingly.
# partial:
<%= f.collection_select(:customer, @customers,
:customer_id, :customer_name, {:prompt=>'Select a Customer'})%>
<div id='display'></div>
這裏的每一個link_to_add獨特div編號是我的問題:每link_to_add,我想創造出獨特的「顯示」分區,因爲我有填充的是「顯示」 DIV的一個javascript該collection_select的onchange事件。 感謝您的幫助!在一個nested_form