fields_for 内部でパーシャルをリフレッシュする際に問題があります。
これが部分的なコードです(「table_detalle」)
<table class="table">
<thead>
<tr>
<th><%= t('.denominacion') %></th>
<th><%= t('.cantidad_ingreso') %></th>
<th><%= t('.importe') %></th>
</tr>
</thead>
<tbody>
<%= f.fields_for :operacion_detalles do |builder| %>
<tr>
<%= render 'table_detalle_operacion', f: builder %>
</tr>
<% end unless @operacion.nil? %>
</tbody>
</table>
<%= content_tag :h3, t('.total', :value=> number_to_currency(@operacion.R_IMPORTE)).html_safe, :class => 'pull-right', style: 'display:inline' %>
ユーザーがコンボの値を変更すると、上記の部分を更新したいと思います (詳細オブジェクトを変更する必要があり、編集可能であるため)
JavaScriptコードは次のとおりです。
$('#operacion_TIPOVALOR_ID').change(function(){
$.ajax({
url: '<%= cambiar_tipo_valor_movimientos_path %>',
data: {tipo_valor_id: $('#operacion_TIPOVALOR_ID').val()},
complete: function(){
$('#tipo_valor_loader').css('display','none');
},
beforeSend: function(){
$('#tipo_valor_loader').css('display','inline');
},
success: null,
dataType: 'script'
});
});
コントローラーコード:
def cambiar_tipo_valor
@operacion = Operacion.new
denominaciones = TipoValorDenominacion.all_from_tipo_valor params[:tipo_valor_id]
denominaciones.each do |deno|
@operacion.operacion_detalles.build :tipo_valor_denominacion => deno, :I_CANTIDAD => 0, :R_IMPORTE => 0
end
end
ユーザーの選択に応じて「operacion_detalles」が変化することがわかります。
.js.erb コード:
$('#detalle').html('<%= escape_javascript(render :partial => 'table_detalle') %>');
しかし、私は得る:
undefined local variable or method `f' for #<#<Class:0x45ae1c8>:0x5062338>
したがって、パーシャルをレンダリングするには f 変数が必要です。f 変数をエミュレートする方法はありますか?
前もって感謝します。