こんにちは皆さん、ここで動的選択を試みています。顧客を選択するとすぐに、請求書の合計値がテキスト フィールド タグに表示されます。
景色
jQuery(document).ready(function(){
jQuery(".customerid").bind("change", function() {
var data = {
customer_id: jQuery(".customerid :selected").val()
}
jQuery.ajax({
url: "get_cust_bill",
type: 'GET',
dataType: 'script',
data: data
});
});
});
</script>
<div class ="customerid"><%= f.label :customer_id %>
<%= f.collection_select :customer_id, Customer.all, :id, :name, options ={:prompt => "-Select a Customer"}, :class => "state", :style=>'width:210px;'%></div><br />
<div class ="customerbill">
<%= f.label :total_value, "Total Value" %>
<%= render :partial => "customerbill" %>
js.erb ファイル
jQuery('.customerbill').html("<%= escape_javascript(render :partial => 'customerbill') %>");
顧客請求書の部分
<% options = []
options = @cust_bill.total_value if @cust_bill.present? %>
<%= text_field_tag "total_value", options %>
コントローラーで
def get_cust_bill
@cust_bill = CustomerBill.find_all_by_customer_id(params[:customer_id]) if params[:customer_id]
end
問題はパーシャルにあると感じています。私が呼び出している方法なoptions
ので、テキストフィールドで値を取得する方法を教えてもらえますか??? 少し早いですがお礼を。