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



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

def create
  @user = User.new(user_params)

  if while_signup?
    
  else
    create_user_or_redirect
  end
end

#destroyObject



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

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



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

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



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

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

#signupObject



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

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

#updateObject



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

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