Class: Admin::CaptainOveur::UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/captain_oveur/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#activate_adminObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/admin/captain_oveur/users_controller.rb', line 58

def activate_admin
  @user = User.find(params[:id])
  respond_to do |format|
    if @user.activate_admin!
      flash[:msg] = "User #{@user.email} was promoted to Admin."
      format.html do
        redirect_to edit_admin_user_path(@user)
      end
    else
      format.html do
        flash[:msg] = "User #{@user.email} could not be promoted to Admin."
        render :action => :edit
      end
    end
  end
end

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/admin/captain_oveur/users_controller.rb', line 16

def create 
  @user = User.new(params[:user])
  respond_to do |format|
    if @user.save
      flash[:msg] = "User created."
      format.html do
        redirect_to admin_user_path(@user)
      end
    else
      format.html do
        render :action => :new
      end
    end
  end
end

#deactivate_adminObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/admin/captain_oveur/users_controller.rb', line 75

def deactivate_admin
  @user = User.find(params[:id])
  respond_to do |format|
    if @user.deactivate_admin!
      flash[:msg] = "User #{@user.email} was demoted from Admin."
      format.html do
        redirect_to edit_admin_user_path(@user)
      end
    else
      format.html do
        flash[:msg] = "User #{@user.email} could not be demoted from Admin."
        render :action => :edit
      end
    end
  end
end

#destroyObject



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/admin/captain_oveur/users_controller.rb', line 97

def destroy
  @user = User.find(params[:id])
  respond_to do |format|
    if current_user.id != @user.id && @user.destroy
      flash[:msg] = "User deleted."
    else
      flash[:msg] = "User could not be deleted."
    end
    format.html do
      redirect_to admin_users_path
    end
  end
end

#editObject



32
33
34
35
# File 'app/controllers/admin/captain_oveur/users_controller.rb', line 32

def edit
  @user = User.find(params[:id])
  render :template => "admin/users/edit.html.erb"
end

#indexObject



6
7
8
9
# File 'app/controllers/admin/captain_oveur/users_controller.rb', line 6

def index
  @users = User.all
  render :template => "admin/users/index.html.erb"
end

#newObject



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

def new
  @user = User.new
  render :template => "admin/users/new.html.erb"
end

#showObject



92
93
94
95
# File 'app/controllers/admin/captain_oveur/users_controller.rb', line 92

def show
  @user = User.find(params[:id])
  render :template => "admin/users/show.html.erb"
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/admin/captain_oveur/users_controller.rb', line 37

def update
  @user = User.find(params[:id])
  if params[:user_admin] and params[:user_admin] == 1
    @user.activate_admin!
  else
    @user.deactivate_admin!
  end
  respond_to do |format|
    if @user.update_attributes(params[:user])
      flash[:msg] = "User #{@user.email} was successfully updated."
      format.html do
        redirect_to admin_users_path
      end
    else
      format.html do
        render :action => :edit
      end
    end
  end
end