Class: Admin::UsersController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#fresh_when, #redirect_back_or_default, #redirect_referrer_or_default, #render_403, #render_404, #render_optional_error_file, #require_user, #set_active_menu, #set_locale, #set_seo_meta, #store_location, #unread_notify_count

Instance Method Details

#createObject


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/admin/users_controller.rb', line 25

def create
  @user = User.new(params[:user].permit!)
  @user.email = params[:user][:email]
  @user. = params[:user][:login]
  @user.state = params[:user][:state]
  @user.verified = params[:user][:verified]

  if @user.save
    redirect_to(admin_users_path, notice: 'User was successfully created.')
  else
    render action: 'new'
  end
end

#destroyObject


53
54
55
56
57
58
# File 'app/controllers/admin/users_controller.rb', line 53

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

  redirect_to(admin_users_url)
end

#editObject


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

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

#indexObject


3
4
5
6
7
8
9
10
# File 'app/controllers/admin/users_controller.rb', line 3

def index
  @users = User.all
  if params[:q]
    qstr = "%#{params[:q]}%"
    @users = @users.where('login LIKE ? or email LIKE ?', qstr, qstr)
  end
  @users = @users.order(id: :desc).paginate page: params[:page], per_page: 30
end

#newObject


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

def new
  @user = User.new
  @user._id = nil
end

#showObject


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

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

#updateObject


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/admin/users_controller.rb', line 39

def update
  @user = User.find_login!(params[:id])
  @user.email = params[:user][:email]
  @user. = params[:user][:login]
  @user.state = params[:user][:state]
  @user.verified = params[:user][:verified]

  if @user.update_attributes(params[:user].permit!)
    redirect_to(edit_admin_user_path(@user.id), notice: 'User was successfully updated.')
  else
    render action: 'edit'
  end
end