Мне нужно знать, как искать всю комиссию банка, находящегося в таблице bankcommission, после выбора имени банка при выборе коллекции. Я хочу показать список с% комиссией, которая вернула базу данных в той же форме, мне нужно показать общее количество комиссий за скидку, которые я пробовал jquery, как это видео https://www.youtube.com/watch?v=j1zZ4Lgzf9s
это код, который я пробую с видео
jQuery ->
vbankcom = $('#bankcommission_banco_id').html()
$('#mov_ingreso_debe').change ->
vmovbank = $('#mov_ingreso_banco_id').text()
options = $(vbankcom).filter("optgroup[label='#{vmovbank}']").html()
if options
$('#bankcommission_banco_id').html(options)
else
$('#bankcommission_banco_id').empty()
это мой контроллер
class MovIngresosController < ApplicationController
before_action :set_movingreso, except: [:index,:new,:create]
before_action :set_mov_commission
def new
@mov_ingreso = MovIngreso.new
@mov_principal = @mov_ingreso.build_mov_principal
end
def index
@mov_ingresos = MovIngreso.all
@mov_ingresos = MovIngreso.order('date_set DESC').reorder('id DESC')
end
def edit
end
def update
@mov_ingreso.mov_principal.date_update = Date.today
if @mov_ingreso.update_attributes(movingreso_params)
flash[:success]= "Ingreso actualizado"
redirect_to action: 'index'
end
end
def create
@mov_ingreso = MovIngreso.new (movingreso_params)
@mov_ingreso.mov_principal.user_id = current_user.id
@mov_ingreso.mov_principal.date_update = Date.today
if @mov_ingreso.save
redirect_to action: 'index'
else
render :new
end
end
def destroy
@mov_ingreso.destroy
redirect_to action: 'index'
end
private
def set_movingreso
@mov_ingreso = MovIngreso.find(params[:id])
end
def set_mov_commission
@bankcommission = Bankcommission.where(activo: '1')
end
def movingreso_params
params.require(:mov_ingreso)
.permit(:debe,
mov_principal_attributes:[:id,:referencia,:id_tipo,:banco_id,:date_set,:date_update,:user_id,:_destroy,:nivele_id,])
end
end
моя модель
bankcommission.rb
class Bankcommission < ApplicationRecord
belongs_to :tipo_concepto, :class_name => 'TipoConcepto '
belongs_to :banco
end
movingreso.rb
class MovIngreso < ActiveRecord::Base
self.table_name = 'mov_ingreso'
belongs_to :mov_principal , :class_name => 'MovPrincipal'
accepts_nested_attributes_for :mov_principal, :allow_destroy => true
has_many :puntos, :class_name => 'Punto'
end
_newform. html. erb
<% @mov_ingreso.errors.full_messages.each do |message| %>
<div class="be-red white top-space">
* <%= message %>
</div>
<% end %>
<%= ingreso.fields_for :mov_principal do |f| %>
<div class="form-group row">
<label class="col-sm-2 col-form-label"> <%= f.label :referencia, "Referencia" %> </label>
<div class="col-sm-10">
<%= f.text_field :referencia, class: 'form-control', placeholder: "N° DE REFERENCIA" %>
</div>
</div>
<div class="form-group row" >
<label class="col-sm-2 col-form-label"> <%= f.label :id_tipo, "Tipo" %> </label>
<div class="col-sm-10">
<%= f.collection_select(:id_tipo, TipoConcepto.where(:forma => "1"), :id, :tipo,{:prompt => "SELECCIONE EL TIPO DE INGRESO"}, {class: 'custom-select'}) %>
</div>
</div>
<div class="form-group row" >
<label class="col-sm-2 col-form-label"> <%= f.label :nivele_id, "Niveles" %> </label>
<div class="col-sm-10">
<%= f.collection_select(:nivele_id, Nivele.where(:tipo_movimiento_id => "1"), :id, :descripcion,{:prompt =>"SELECCIONE EL NIVEL"} ,{class: 'custom-select'} ) %>
</div>
</div>
<div class="form-group row" >
<label class="col-sm-2 col-form-label"> <%= f.label :id_banco, "Banco" %> </label>
<div class="col-sm-10">
<%= f.collection_select(:banco_id, Banco.all, :id, :nombre,{:prompt =>"SELECCIONE EL BANCO"} ,{class: 'custom-select'} ) %>
</div>
</div>
<div class="form-group row" >
<label class="col-sm-2 col-form-label"> <%= f.label :date_set, "Fecha" %> </label>
<div class="col-sm-10">
<%= f.text_field :date_set, class: 'form-control', data: { provide: "datepicker",
'date-format': 'dd-mm-yyyy',
'date-autoclose': 'true',
'date-today-btn': 'linked',
'date-today-highlight': 'true'}, value: Time.now.strftime('%d-%m-%Y') %>
</div>
</div>
<% end %>
<div class="form-group row" >
<label class="col-sm-2 col-form-label"> <%= ingreso.label :debe, "Monto" %> </label>
<div class="col-sm-10">
<%= ingreso.text_field :debe, class: 'form-control montobase' , placeholder: "MONTO DE INGRESO" %>
</div>
</div>
<div class = "field">
<%= ingreso.submit "Guardar", class:"guardo btn btn-primary" %>
</div>
_totalform. html .erb
<div class="table-responsive">
<table class="table table-borderless table-hover table-centered m-0">
<thead class="thead-light text-left">
<tr>
<th scope="col">Comision</th>
<th scope="col">%</th>
<th scope="col">Total</th>
</tr>
</thead>
<tbody>
<% @bankcommission.each do |ingresos| %>
<tr class="text-left">
<td><%=ingresos.descrip %></td>
<td><%= number_with_precision( ingresos.pvalue, precision: 2, separator: ',', delimiter: '.') %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
Спасибо