Added ransack search function to admin/users index

This commit is contained in:
2024-09-18 14:59:07 +02:00
parent 4bff15cd4e
commit ff1c1017cf
11 changed files with 77 additions and 21 deletions

View File

@@ -1,4 +1,6 @@
class Admin::JobsController < ApplicationController
include Pagy::Backend
before_action :authorize!
def index
@jobs = Job.all

View File

@@ -1,10 +1,14 @@
class Admin::UsersController < ApplicationController
include Pagy::Backend
before_action :set_user, only: [ :show, :update ]
before_action :authorize!
def index
@users = User.all.order(:lastname, :firstname)
@pagy, @records = pagy(@users, limit: 20)
# @users = User.all.order(:lastname, :firstname)
@q = User.ransack(params[:q])
@q.sorts = "id asc" if @q.sorts.empty?
@pagy, @records = pagy(@q.result(distinct: true), limit: 20)
end
def edit
@@ -23,7 +27,7 @@ class Admin::UsersController < ApplicationController
authorize! @user
if @user.update(user_params)
respond_to do |format|
format.html { redirect_to admin_users_path }
format.html { redirect_back(fallback_location: admin_users_path) }
end
else
render :index, status: :unprocessable_entity

View File

@@ -1,6 +1,4 @@
class ApplicationController < ActionController::Base
include Pagy::Backend
before_action :set_current_request_details
before_action :authenticate_user!
before_action :verified_user!