我正在尝试根据person
auser
在表单中选择的选项更新单选选项列表。
_fields.html.erb:
<%= f.label :person %>
<%= f.select(:person_id, current_user.person_names) %>
<%= f.label :invoice_type %>
<%= radio_buttons_collection(f.object.invoice_types, f) %>
application_helper.rb:
def radio_buttons_collection(types, f) # works, but not with Ajax!
types_html = types.map do |type|
f.radio_button(:invoice_type, type)
end
safe_join(types_html)
end
项目控制器.rb:
def get_invoice_types
person = Person.find(params[:person_id])
@types = person.address_types
end
get_invoice_types.js.erb:
$('#project_invoice_type').html("<%= escape_javascript(radio_buttons_collection(@types, f)) %>");
应用程序.js:
$("#project_person_id").change(function() {
$.ajax({
url: '/projects/get_invoice_types',
data: 'person_id=' + this.value,
dataType: 'script'
})
});
person
一切正常,除了单选选项在表单中更改时不会更新。
谁能告诉我该怎么做?
谢谢你的帮助。