Tengo la aplicación Rails 5, donde intento agregar la capacidad de ordenar la tabla a través de encabezados en los que se puede hacer clic. Traté de usar ransack gem pero tengo algunos problemas descritosaquí . Como alternativa, encontré una biblioteca JS realmente agradable llamada sortable.js de este sitio https://kryogenix.org/code/browser/sorttable/ . Seguí las instrucciones, todo lo que tenía que hacer era:
sorttable.js en app/assets/javascripts/sorttable.js<script src="sorttable.js"></script> en la parte superior de mi _pending.list.html.erbsortable en la clase de tabla _pending.list.html.erb
<main role="main"> <div class="left-margin-row top-buffer"> <div class="col-md-10"> <% if pending_caregiver_authorizations.any? %> <div class="multi-modal"> <table class="table table-striped table-bordered sortable"> <thead> <tr> <th>Name</th> <th>Patients</th> <th>Requested on</th> </tr> </thead> <tbody> <% pending_caregiver_authorizations.each do |authorization| %> <tr> <td><%= link_to "#{authorization.registrant.first_name}", registrant_path(authorization.registrant) %></td> <td><%= authorization.created_at.in_time_zone(Time.zone) %></td> </tr> <% end %> </tbody> </table> </div> <% else %> <h5>No pending authorizations</h5> <% end %> </div> </div> </main>Con el código anterior me sale un error:
ActionController::RoutingError (No route matches [GET] "/caregiver_authorizations/sorttable.js"): Si muevo el archivo sorttable.js a la misma carpeta donde vive _pending.list.html.erb parcial, obtendré el mismo error.
[Editar]
application.js
//= require jquery //= require jquery_ujs //= require jquery.fileDownload //= require jquery.dataTables.min //= require bootstrap-sprockets //= require bootstrap-datepicker/core //= require bootstrap-select //= require turbolinks //= require_tree .