I'm trying to make a select to filter a table, with had 2 entries, annual and monthly, i need the table to change as the user select on the options. I trying do that using the if along with the view, but not seens to work. Heres how my code are until now.
On home_controller:
def top_regions
state_name = t :states, scope: 'date'
query = @current_account.coaches.top_regions_year
.select('addresses.state_name, sum(coalesce(coaches.credits_purchased,0)) as credits')
.left_outer_joins(person: :address)
.group('addresses.state_name')
.order('credits DESC')
.limit(10)
@topregions1 = (query)
query = @current_account.coaches.top_regions_month
.select('addresses.state_name, sum(coalesce(coaches.credits_purchased,0)) as credits')
.left_outer_joins(person: :address)
.group('addresses.state_name')
.order('credits DESC')
.limit(10)
@topregions2 = (query)
end
On view:
%legend.c-indicators__legend.d-flex.justify-content-between
Regiões mais Ativas
%select.form-control.d-flex.align-items-end.col-4
%option{:value => "1"} Anual
%option{:value => "2"} Mensal
.c-indicators__card
%table.table.c-table.table-striped.m-3
%thead
%tr
%th Pos.
%th Estado
%th{:align => "right"} Total de Testes
%tbody
- @topregions.each_with_index do |item, index|
%tr
%td= (index + 1)
%td= item[:state_name]
%td{:align => "right"}= item[:credits]
The two @topregions options that i had in the controller works, if a put the @topregions1 or topregions2 on the view, but i need the dynamic change when selected
Aucun commentaire:
Enregistrer un commentaire