person
Rails に ajax 関数があり、フォームで選択されたに基づいてオプション ハッシュを更新します。
# projects_controller.rb
def get_invoice_types
person = Person.find(params[:person_id])
@types = person.address_types
end
# get_invoice_types.erb
$('#project_invoice_type').html("<%= escape_javascript(options_for_select(@types)) %>");
# application.js
$("#project_person_id").change(function() {
$.ajax({
url: '/projects/get_invoice_types',
data: 'person_id=' + this.value,
dataType: 'script'
})
});
radio_buttons
の代わりに のリストを生成する簡単な方法はありoptions_for_select
ますか?
もしそうなら、どうすればこれを行うことができますか?
助けてくれてありがとう。
これは、私が最終的に得たラジオボックスを生成するための関数です:
def collection_radio_buttons(types, f) # works!
types_html = types.map do |type|
content_tag :span, :class => "radio_option" do
f.radio_button(:invoice_type, type) + localize_address_type(type)
end
end
safe_join(types_html)
end
ただし、上記の Ajax 関数を介して更新することはできません。f
これは、関数に渡された変数が原因だと思いますか?