Class: Alchemy::Admin::UsersController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @user = User.new(user_params)

  if while_signup?
    
  else
    create_user_or_redirect
  end
end

#destroyObject



58
59
60
61
62
63
64
65
# File 'app/controllers/alchemy/admin/users_controller.rb', line 58

def destroy
  # User is fetched via before filter
  name = @user.name
  if @user.destroy
    flash[:notice] = Alchemy.t("User deleted", name: name)
  end
  do_redirect_to admin_users_path
end

#indexObject



14
15
16
17
18
19
20
# File 'app/controllers/alchemy/admin/users_controller.rb', line 14

def index
  @query = User.ransack(params[:q])
  @query.sorts = "login asc" if @query.sorts.empty?
  @users = @query.result
    .page(params[:page] || 1)
    .per(items_per_page)
end

#newObject



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

def new
  @user = User.new(send_credentials: true)
end

#signupObject



26
27
28
29
30
31
32
33
# File 'app/controllers/alchemy/admin/users_controller.rb', line 26

def 
  if while_signup?
    new
  else
    flash[:warning] = Alchemy.t(:cannot_signup_more_then_once)
    redirect_to admin_dashboard_path
  end
end

#updateObject



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

def update
  # User is fetched via before filter
  if params[:user][:password].present?
    @user.update(user_params)
  else
    @user.update_without_password(user_params)
  end
  deliver_welcome_mail
  render_errors_or_redirect @user,
    admin_users_path,
    Alchemy.t("User updated", name: @user.name)
end