Class: UsersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- UsersController
- Includes:
- Pagy::Backend
- Defined in:
- app/controllers/users_controller.rb
Overview
This controller manage the views refering to User model
before_action :#set_user, only: [:show, :edit, :update, :destroy, unlock, trash}
Instance Method Summary collapse
-
#create ⇒ Object
POST /users.
-
#destroy ⇒ Object
DELETE /users/1.
-
#edit ⇒ Object
GET /users/1/edit.
-
#index ⇒ Object
GET /users.
-
#list ⇒ Object
GET /users/list.
-
#new ⇒ Object
GET /users/new.
-
#show ⇒ Object
GET /users/1.
-
#trash ⇒ Object
DELETE /users/1/trash.
-
#unlock ⇒ Object
PATCH /users/1/unlock.
-
#update ⇒ Object
PATCH/PUT /users/1.
Instance Method Details
#create ⇒ Object
POST /users
Create a new User set @user as new User with #user_params as param
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/users_controller.rb', line 58 def create @user = User.new(user_params) if @user.save UsersCheckJob.perform_now(username: @user.username) flash.now[:success] = 'Creazione avvenuta con successo' render turbo_stream: [ turbo_stream.replace(:flashes, partial: "flashes"), turbo_stream.replace(:yield, partial: "users/show", locals: { user: @user.reload, tab: @tab }) ] else flash.now[:error] = write_errors(@user) render turbo_stream: turbo_stream.replace(:flashes, partial: "flashes") end end |
#destroy ⇒ Object
DELETE /users/1
lock a user
-
#set_user has set @user for destroy
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/users_controller.rb', line 94 def destroy if @user.disable! flash.now[:success] = 'Disattivazione avvenuta con successo' render turbo_stream: [ turbo_stream.replace("user_#{@user.id}", partial: 'users/user', locals: {user: @user, current_user: current_user}), turbo_stream.replace(:flashes, partial: "flashes") ] else flash.now[:error] = write_errors(@user) format.turbo_stream { render turbo_stream: turbo_stream.replace(:flashes, partial: "flashes") } end end |
#edit ⇒ Object
GET /users/1/edit
Render the form for edit a user #set_user has set @user for edit
51 |
# File 'app/controllers/users_controller.rb', line 51 def edit; end |
#index ⇒ Object
GET /users
render users index set @pagy, @users for the users pagination
16 |
# File 'app/controllers/users_controller.rb', line 16 def index; end |
#list ⇒ Object
GET /users/list
render users list set @pagy, @users for the users pagination
23 24 25 26 |
# File 'app/controllers/users_controller.rb', line 23 def list users flash.now[:success] = 'Caricamento completato' end |
#new ⇒ Object
GET /users/new
Render the form for create a new user set @user as new User
42 43 44 |
# File 'app/controllers/users_controller.rb', line 42 def new @user = User.new end |
#show ⇒ Object
GET /users/1
render users show
32 33 34 35 |
# File 'app/controllers/users_controller.rb', line 32 def show @view = params[:view] || '' @current_ability.cannot(:manage, @user) if @view == 'modal' end |
#trash ⇒ Object
DELETE /users/1/trash
destroy a user
-
#set_user has set @user for destroy
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/controllers/users_controller.rb', line 132 def trash @user.forced = 'true' if @user.destroy flash.now[:success] = 'Cancellazione avvenuta con successo' render turbo_stream: [ turbo_stream.remove("user_#{@user.id}"), turbo_stream.replace(:flashes, partial: "flashes") ] else flash.now[:error] = write_errors(@user) render turbo_stream: turbo_stream.replace(:flashes, partial: "flashes") end end |
#unlock ⇒ Object
PATCH /users/1/unlock
unlock a user
-
#set_user has set @user for unlock
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/controllers/users_controller.rb', line 113 def unlock if @user.enable! flash.now[:success] = 'Riattivazione avvenuta con successo' render turbo_stream: [ turbo_stream.replace("user_#{@user.id}", partial: 'users/user', locals: {user: @user, current_user: current_user}), turbo_stream.replace(:flashes, partial: "flashes") ] else flash.now[:error] = write_errors(@user) render turbo_stream: turbo_stream.replace(:flashes, partial: "flashes") end end |
#update ⇒ Object
PATCH/PUT /users/1
update a user #set_user has set @user for update and update with #user_params as param
79 80 81 82 83 84 85 86 |
# File 'app/controllers/users_controller.rb', line 79 def update if @user.update(user_params) flash.now[:success] = 'Modifica avvenuta con successo' else flash.now[:error] = write_errors(@user) end render turbo_stream: turbo_stream.replace(:flashes, partial: "flashes") end |