Class: UsersController

Inherits:
ApplicationController show all
Defined in:
lib/branston/app/controllers/users_controller.rb,
lib/branston/test/functional/users_controller_test.rb

Overview

Re-raise errors caught by the controller.

Instance Method Summary collapse

Instance Method Details

#activateObject



63
64
65
66
# File 'lib/branston/app/controllers/users_controller.rb', line 63

def activate
  @user.activate!
  redirect_to users_path
end

#createObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/branston/app/controllers/users_controller.rb', line 32

def create
  @user = User.new(params[:user])
  @user.role = params[:user][:role] if current_user.has_role?("admin")
  if @user && @user.valid? && @user.save!
    redirect_to users_url
    flash[:notice] = "User created."
  else
    flash[:error]  = "We couldn't set up that account, sorry.  Please try again, or contact an admin (link is above)."
    render :action => 'new'
  end
end

#destroyObject



68
69
70
71
# File 'lib/branston/app/controllers/users_controller.rb', line 68

def destroy
  @user.delete!
  redirect_to users_path
end

#editObject



44
45
46
# File 'lib/branston/app/controllers/users_controller.rb', line 44

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

#indexObject



24
25
26
# File 'lib/branston/app/controllers/users_controller.rb', line 24

def index
  @users = User.find(:all)
end

#newObject



28
29
30
# File 'lib/branston/app/controllers/users_controller.rb', line 28

def new
  @user = User.new
end

#rescue_action(e) ⇒ Object



5
# File 'lib/branston/test/functional/users_controller_test.rb', line 5

def rescue_action(e) raise e end

#suspendObject



58
59
60
61
# File 'lib/branston/app/controllers/users_controller.rb', line 58

def suspend
  @user.suspend!
  redirect_to users_path
end

#updateObject



48
49
50
51
52
53
54
55
56
# File 'lib/branston/app/controllers/users_controller.rb', line 48

def update
  @user = User.find(params[:id])
  @user.role = params[:user][:role] if current_user.has_role?("admin")
  if @user.update_attributes(params[:user])
    redirect_to users_path
  else
    render :action => 'edit'
  end
end