## 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,因为我有一个javascript,它使用该collection_select 的onchange 事件填充该“显示” div。感谢您的帮助!