Class: Admin::UsersController

Inherits:
ForestController
  • Object
show all
Includes:
FilterControllerScopes
Defined in:
app/controllers/admin/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /users



33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/admin/users_controller.rb', line 33

def create
  @user = User.new(user_params)
  authorize @user

  if @user.save
    redirect_to edit_admin_user_path(@user), notice: 'User was successfully created.'
  else
    render :new
  end
end

#destroyObject

DELETE /users/1



72
73
74
75
76
# File 'app/controllers/admin/users_controller.rb', line 72

def destroy
  authorize @user
  @user.destroy
  redirect_to admin_users_url, notice: 'User was successfully destroyed.'
end

#editObject

GET /users/1/edit



28
29
30
# File 'app/controllers/admin/users_controller.rb', line 28

def edit
  authorize @user
end

#indexObject

GET /users



11
12
13
14
# File 'app/controllers/admin/users_controller.rb', line 11

def index
  @users = apply_scopes(User.includes(:user_groups)).by_id.page params[:page]
  authorize @users
end

#newObject

GET /users/new



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

def new
  @user = User.new
  authorize @user
end

#reset_passwordObject



60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/admin/users_controller.rb', line 60

def reset_password
  @user = User.find(params[:user_id])
  authorize @user

  if @user.send_reset_password_instructions
    redirect_to edit_admin_user_path(@user), notice: 'User password reset link was successfully sent.'
  else
    render :edit
  end
end

#showObject

GET /users/1



17
18
19
# File 'app/controllers/admin/users_controller.rb', line 17

def show
  authorize @user
end

#updateObject

PATCH/PUT /users/1



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/admin/users_controller.rb', line 45

def update
  authorize @user

  if params[:user][:password].blank? && params[:user][:password_confirmation].blank?
    params[:user].delete(:password)
    params[:user].delete(:password_confirmation)
  end

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