Class: Admin::UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/users_controller.rb

Overview

This controller manage the User model for the admins

Instance Method Summary collapse

Instance Method Details

#editObject

GET /admin/users/:id/edit


24
25
26
# File 'app/controllers/admin/users_controller.rb', line 24

def edit
  @groups = Group.all.order(:title).pluck :title, :id
end

#filter_paramsObject (private)

Filter params for search an User


50
51
52
# File 'app/controllers/admin/users_controller.rb', line 50

def filter_params
  params.fetch(:filter, {}).permit(:text, :editor, :admin)
end

#indexObject

GET /admin/users


8
# File 'app/controllers/admin/users_controller.rb', line 8

def index; end

#listObject

GET /admin/users/list.html GET /admin/users/list.json


12
13
14
15
16
17
18
# File 'app/controllers/admin/users_controller.rb', line 12

def list
  @search = {}
  @search[:editor] = true if filter_params[:editor] == '1'
  @search[:admin] = true if filter_params[:admin] == '1'
  @text = ['username ilike :text', { text: "%#{filter_params[:text]}%" }] if filter_params[:text].present?
  @pagy, @users = pagy(User.where(@search).where(@text))
end

#set_userObject (private)

set @user when needed


40
41
42
# File 'app/controllers/admin/users_controller.rb', line 40

def set_user
  @user = User.find(params[:id])
end

#showObject

GET /admin/users/:id


21
# File 'app/controllers/admin/users_controller.rb', line 21

def show; end

#updateObject

PATCH/PUT /admin/users/:id


29
30
31
32
33
34
35
# File 'app/controllers/admin/users_controller.rb', line 29

def update
  if @user.update(user_params)
    redirect_to admin_user_path(@user), notice: 'User was successfully updated.'
  else
    render :edit
  end
end

#user_paramsObject (private)

Filter params for set an User


45
46
47
# File 'app/controllers/admin/users_controller.rb', line 45

def user_params
  params.require(:user).permit(:editor, :admin, group_ids: [])
end