Class: Admin::UsersController

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

Instance Method Summary collapse

Methods included from BlogHelper

#blog_base_url, #this_blog

Instance Method Details

#createObject



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

def create
  @user = User.new(user_params)
  @user.name = @user.
  if @user.save
    redirect_to admin_users_url, notice: I18n.t("admin.users.new.success")
  else
    render :new
  end
end

#destroyObject



40
41
42
43
# File 'app/controllers/admin/users_controller.rb', line 40

def destroy
  @user.destroy if User.where("profile = ? and id != ?", User::ADMIN, @user.id).count > 1
  redirect_to admin_users_url
end

#editObject



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

def edit
  @user = params[:id] ? User.find_by(id: params[:id]) : current_user
end

#indexObject



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

def index
  @users = User.order("login asc").page(params[:page])
    .per(this_blog.admin_display_elements)
end

#newObject



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

def new
  @user = User.new
  @user.text_filter_name = this_blog.text_filter
end

#updateObject



30
31
32
33
34
35
36
37
38
# File 'app/controllers/admin/users_controller.rb', line 30

def update
  if @user.update(update_params)
    flash[:notice] = I18n.t("admin.base.successfully_updated",
                            name: User.model_name.human)
    redirect_to admin_users_url
  else
    render :edit
  end
end