Class: Cmtool::UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/cmtool/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
# File 'app/controllers/cmtool/users_controller.rb', line 21

def create
  @user = ::User.new(params[:user])
  if @user.save
    redirect_to cmtool.users_path, :notice => I18n.t('cmtool.action.create.successful', :model => ::User.model_name.human)
  else
    render :action => 'new'
  end
end

#destroyObject



48
49
50
51
52
# File 'app/controllers/cmtool/users_controller.rb', line 48

def destroy
  @user = ::User.find(params[:id])
  @user.destroy
  redirect_to cmtool.users_path, :notice => I18n.t('cmtool.action.destroy.successful', :model => ::User.model_name.human)
end

#editObject



13
14
15
# File 'app/controllers/cmtool/users_controller.rb', line 13

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

#indexObject

GET /cmtool/users



5
6
7
# File 'app/controllers/cmtool/users_controller.rb', line 5

def index
  @users = ::User.all
end

#newObject



17
18
19
# File 'app/controllers/cmtool/users_controller.rb', line 17

def new
  @user = ::User.new
end

#showObject



9
10
11
# File 'app/controllers/cmtool/users_controller.rb', line 9

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

#updateObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/cmtool/users_controller.rb', line 30

def update
  user = params[:user]
  unless user['password'].present?
    user.delete('password')
    user.delete('password_confirmation')
  end
  @user = ::User.find(params[:id])
  if @user.update_attributes(user)
    if user['password']
      # Sign in after changing current logged in password
      (@user, :bypass => true) if @user == current_user
    end
    redirect_to cmtool.users_path, :notice => I18n.t('cmtool.action.update.successful', :model => ::User.model_name.human)
  else
    render :action => 'edit'
  end
end