Class: Admin::AdminsController

Inherits:
AdminController show all
Defined in:
app/controllers/admin/admins_controller.rb

Instance Method Summary collapse

Methods inherited from SlicesController

should_raise_exceptions?

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
# File 'app/controllers/admin/admins_controller.rb', line 27

def create
  @admin = Admin.new(params[:admin])
  if @admin.save
    redirect_to admin_admins_path
  else
    render action: :show
  end
end

#destroyObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/admin/admins_controller.rb', line 56

def destroy
  admin = Admin.find(params[:id])
  if admin == current_admin
    render text: '', status: 409
  else
    admin.destroy
    respond_to do |format|
      format.html { redirect_to admin_admins_path }
      format.json { render json: true }
    end
  end
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/admin/admins_controller.rb', line 6

def index
  admins = Admin.all
  if params.has_key?(:search) && params[:search].present?
    admins = admins.text_search(params[:search])
  end

  respond_to do |format|
    format.html
    format.json do
      params[:per_page] = 50 unless params.include?(:per_page)
      params[:per_page] = params[:per_page].to_i
      render json: jsonify_with_current_admin(admins.paginate(params))
    end
  end
end

#newObject



22
23
24
25
# File 'app/controllers/admin/admins_controller.rb', line 22

def new
  @admin = Admin.new
  render action: :show
end

#showObject



36
37
38
39
# File 'app/controllers/admin/admins_controller.rb', line 36

def show
  @admin = Admin.find(params[:id])
  respond_with(@admin)
end

#updateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/admin/admins_controller.rb', line 41

def update
  admin_params = params[:admin]
  if admin_params[:password].blank?
    admin_params.delete(:password)
    admin_params.delete(:password_confirmation)
  end
  @admin = Admin.find(params[:id])
  @admin.update_attributes(admin_params)
  if @admin.valid?
    redirect_to admin_admin_path(@admin)
  else
    render action: :show
  end
end