Class: Admin::UsersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ApplicationController
- Admin::UsersController
- Defined in:
- app/controllers/admin/users_controller.rb
Overview
This controller manage the User model for the admins
Instance Method Summary collapse
-
#edit ⇒ Object
GET /admin/users/:id/edit.
-
#filter_params ⇒ Object
private
Filter params for search an User.
-
#index ⇒ Object
GET /admin/users.
-
#set_user ⇒ Object
private
set @user when needed.
-
#update ⇒ Object
PATCH/PUT /admin/users/:id.
-
#user_params ⇒ Object
private
Filter params for set an User.
Methods inherited from ApplicationController
Methods inherited from ApplicationController
#access_denied!, #default_url_options, #record_not_found!, #set_turbo, #switch_locale
Instance Method Details
#edit ⇒ Object
GET /admin/users/:id/edit
19 20 21 |
# File 'app/controllers/admin/users_controller.rb', line 19 def edit @groups = Group.all.order(:title).pluck :title, :id end |
#filter_params ⇒ Object (private)
Filter params for search an User
46 47 48 |
# File 'app/controllers/admin/users_controller.rb', line 46 def filter_params params.fetch(:filter, {}).permit(:text, :category) end |
#index ⇒ Object
GET /admin/users
9 10 11 12 13 14 15 16 |
# File 'app/controllers/admin/users_controller.rb', line 9 def index @categories = [ "Admin", "Editor" ] @search = {} @search[:editor] = true if filter_params[:category] == "Editor" @search[:admin] = true if filter_params[:category] == "Admin" @text = [ "email ilike :text", { text: "%#{filter_params[:text]}%" } ] if filter_params[:text].present? @pagy, @users = pagy(User.where(@search).where(@text)) end |
#set_user ⇒ Object (private)
set @user when needed
36 37 38 |
# File 'app/controllers/admin/users_controller.rb', line 36 def set_user @user = User.find(params[:id]) end |
#update ⇒ Object
PATCH/PUT /admin/users/:id
24 25 26 27 28 29 30 31 |
# File 'app/controllers/admin/users_controller.rb', line 24 def update if @user.update(user_params) redirect_to admin_users_path, notice: "User was successfully updated." else @groups = Group.all.order(:title).pluck :title, :id render :edit end end |
#user_params ⇒ Object (private)
Filter params for set an User
41 42 43 |
# File 'app/controllers/admin/users_controller.rb', line 41 def user_params params.require(:user).permit(:editor, :admin, group_ids: []) end |