Class: Admin::UsersController

Inherits:
Noodall::Admin::BaseController
  • Object
show all
Includes:
Canable::Enforcers, SortableTable::App::Controllers::ApplicationController
Defined in:
app/controllers/admin/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /users POST /users.xml



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

def create
  @user = User.new(params[:user])
  respond_to do |format|
    if @user.save
      flash[:notice] = 'User was successfully created.'
      format.html { redirect_to(admin_users_url) }
      format.xml  { render :xml => @user, :status => :created, :location => @user }
    else
      format.html { render :action => "show" }
      format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /users/1 DELETE /users/1.xml



71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/admin/users_controller.rb', line 71

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

  @user.destroy
  flash[:notice] = 'User was successfully deleted.'

  respond_to do |format|
    format.html { redirect_to(admin_users_url) }
    format.xml  { head :ok }
  end
end

#groupsObject

Uses tag cloud to render all groups



84
85
86
# File 'app/controllers/admin/users_controller.rb', line 84

def groups
  render :json => User.tag_cloud
end

#indexObject

GET /users GET /users.xml



9
10
11
12
13
14
15
16
# File 'app/controllers/admin/users_controller.rb', line 9

def index
  @users = User.paginate :page => params[:page], :per_page => 20, :order => sort_order(:default => 'asc')

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @users }
  end
end

#newObject

GET /users/new GET /users/new.xml



20
21
22
23
# File 'app/controllers/admin/users_controller.rb', line 20

def new
  @user = User.new
  render :action => 'show'
end

#showObject

GET /users/1/edit



26
27
28
# File 'app/controllers/admin/users_controller.rb', line 26

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

#updateObject

PUT /users/1 PUT /users/1.xml



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/admin/users_controller.rb', line 48

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

  # Remove password params if blank so devise does not validate them
  if params[:user][:password].blank?
    params[:user].delete(:password)
    params[:user].delete(:password_confirmation)
  end

  respond_to do |format|
    if @user.update_attributes(params[:user])
      flash[:notice] = 'User was successfully updated.'
      format.html { redirect_to(admin_users_url) }
      format.xml  { head :ok }
    else
      format.html { render :action => "show" }
      format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
    end
  end
end