0
3アプリケーションのみ初めてで呼び出され、AJAX要求を送信のonchangeイベント、とselect_tagがあります:js.erbが私のレールで
f.select 'forma_id', @collection, {:include_blank => true}, {:onchange => "goAjax('/lancamentos/receber_forma', this.value)", :class => 'btn'}
、goAjaxです:
function goAjax(_url, _value) {
$.ajax({url: _url, data: 'value=' + _value, dataType: 'script'})
}
lancamentos_controller#1 receber_forma(簡易版)である。
def receber_forma
@lancamento = Lancamento.new(:forma_id => params[:value])
logger.info 'forma_id = ' + @lancamento.forma_id
respond_to do |format|
format.html { render :new }
format.js
end
end
とreceber_forma.js.erb:
$('div#cartoes').replaceWith("<%= escape_javascript(label_tag(@lancamento.forma_id)) %>");
何が起こっているのか、私はその選択に値を選択すると、ラベルにレンダリングされた値は常にオン送信された値であるということです最初の呼び出し。次の値の変更は、ラベルテキストを変更しないだけです。メソッドreceber_formaのロガーは、新しい選択値が常に送信されることを示します。
私がここで間違っていることを誰かが知っていますか?
p.s.:sorry英語
感謝ディランの問題を解決した!!!:あなたはおそらくラベルはそれを完全に置き換えるのではなく、
div
の内容になるように、.replaceWith
の代わりに.html
を使用したいです – thaleshcv