Class: DataMigration::UsersController

Inherits:
ApplicationController show all
Includes:
PunditAuthorization
Defined in:
app/controllers/data_migration/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/data_migration/users_controller.rb', line 19

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

  if @user.save
    redirect_to '/data_migration/users', notice: 'User created successfully.'
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



51
52
53
54
55
56
57
58
59
# File 'app/controllers/data_migration/users_controller.rb', line 51

def destroy
  authorize @user

  if @user.destroy
    redirect_to '/data_migration/users', notice: 'User deleted successfully.'
  else
    redirect_to '/data_migration/users', alert: @user.errors.full_messages.join(', ')
  end
end

#editObject



30
31
32
# File 'app/controllers/data_migration/users_controller.rb', line 30

def edit
  authorize @user
end

#indexObject



9
10
11
12
# File 'app/controllers/data_migration/users_controller.rb', line 9

def index
  authorize DataMigrationUser
  @users = policy_scope(DataMigrationUser).ordered_by_email
end

#newObject



14
15
16
17
# File 'app/controllers/data_migration/users_controller.rb', line 14

def new
  authorize DataMigrationUser
  @user = DataMigrationUser.new
end

#updateObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/data_migration/users_controller.rb', line 34

def update
  authorize @user

  # Remove password if blank
  params_to_update = if user_params[:password].blank?
                       user_params.except(:password, :password_confirmation)
                     else
                       user_params
                     end

  if @user.update(params_to_update)
    redirect_to '/data_migration/users', notice: 'User updated successfully.'
  else
    render :edit, status: :unprocessable_entity
  end
end