我正在尝试以下方面.主窗体中的客户选择选项.当用户选择主表单中的客户时,他的账单应出现在所有后续部分中.
我正在使用ryan bates的nested_form gem来获取部分内容.代码如下.
<%= simple_nested_form_for @money_receipt do |f| %>
<div class="customers"><%= f.collection_select :customer_id, Customer.all, :id, :name, options ={:prompt => "-Select a Customer"}, :style=>'width:210px;'%></div><br />
/*rest of the code*/
<%= f.link_to_add "Add line items", :money_receipt_line_items %>
Run Code Online (Sandbox Code Playgroud)
在局部内部
<div class="bill">
<%= f.collection_select :customer_bill_id, CustomerBill.all,:id,:id, {:prompt => "Select Customer bill"}, :style => 'width:202px;' %></div><br />
/*rest of the code*/
Run Code Online (Sandbox Code Playgroud)
上面的jQuery代码如下
jQuery(document).ready(function(){
jQuery(".customers select").bind("change", function() {
var data = {
customer_id: jQuery(this).val()
}
jQuery.getJSON(
"/money_receipts/get_bills",
data, function(data){
var result = "",a,x;
var b …Run Code Online (Sandbox Code Playgroud)