Class: CaptainOveur::UsersController

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

Instance Method Summary collapse

Instance Method Details

#activate_adminObject



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

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



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

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



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

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



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/captain_oveur/users_controller.rb', line 94

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



31
32
33
# File 'app/controllers/captain_oveur/users_controller.rb', line 31

def edit
  @user = User.find(params[:id])
end

#indexObject



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

def index
  @users = User.all
end

#newObject



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

def new
  @user = User.new
end

#showObject



90
91
92
# File 'app/controllers/captain_oveur/users_controller.rb', line 90

def show
  @user = User.find(params[:id])
end

#updateObject



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

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