首页 > 解决方案 > 从视图中使用 ransack 对多列进行排序

问题描述

我正在使用 ransack gem 对视图中的表进行排序,但使用排序功能不允许我同时组合两个或更多列的排序。是否可以使用 ransack 从视图中使用多重排序?

这是我的观点:

<div style="overflow-x:auto;">
  <table class="table">
    <!--<caption>Listado Actualizado...</caption>-->
    <thead>

        <tr>    
          <th scope="col">
            <%= sort_link(@q, :code, 'Código medicamento país') %>
          </th>
          <th scope="col">
            <%= sort_link(@q, :reverse_mx_standar, 'Descripción') %>
          </th>
          <th scope="col">
            <%= sort_link(@q, :reverse_presentacion, 'Presentación') %>
          </th>
          <th scope="col">Acciones</th>
        </tr>
    </thead>
    <tbody id="container_t_drugs_devices">
      <%= render @t_drugs_devices %>
    </tbody>
  </table>
</div>

  <div class="row">
    <div class="col-md-12">
        <%= will_paginate @t_drugs_devices %>
    </div>
  </div>

我的控制器:

  def index

    @q = TDrugsDevice.Busqueda_general(params).por_pais(session[:pais]).ransack(params[:q])
    @t_drugs_devices = @q.result(distinct: true).paginate(page: params[:page]).per_page(params[:por_pagina].to_i)


    respond_to do |format|
      format.html 
      format.js
      format.xls 
    end
  end

我在谷歌搜索,但我得到的是来自控制器的表格组合:

params[:q][:s] = ['reverse_mx_standar asc', 'code asc']

但我不知道如何保存前一个 params[:q] 的值,以便从视图中,用户单击一列,保持前一列排序

标签: ruby-on-railsransack

解决方案


推荐阅读