Class: ConfigManager::AdminsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/config_manager/admins_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /admins



37
38
39
40
41
42
43
44
45
# File 'app/controllers/config_manager/admins_controller.rb', line 37

def create
  @admin = Admin.new admin_params
  if @admin.save
    flash[:notice] = "New admin user #{@admin.email} successfully created"
    redirect_to admins_path
  else
    render "new"
  end
end

#destroyObject

DELETE /admin/:id



48
49
50
51
52
53
54
55
# File 'app/controllers/config_manager/admins_controller.rb', line 48

def destroy
  @admin = Admin.find(params[:id])
  @admin.destroy
  redirect_to admins_path
rescue ActiveRecord::RecordNotFound
  flash[:error] = "Admin with id=#{params[:id]} couldn't be found"
  redirect_to admins_path
end

#editObject

GET /admin/:id/edit



16
17
18
19
20
21
# File 'app/controllers/config_manager/admins_controller.rb', line 16

def edit
  @admin = Admin.find(params[:id])
rescue ActiveRecord::RecordNotFound
  flash[:error] = "Admin with id=#{params[:id]} couldn't be found"
  redirect_to admins_path
end

#indexObject

GET /admins



4
5
6
7
8
# File 'app/controllers/config_manager/admins_controller.rb', line 4

def index
  page = params[:page] || 1
  per_page = params[:page] ? (params[:per_page] || PER_PAGE) : nil
  @admins = Admin.page(page).per(per_page)
end

#newObject

GET /admins/new



11
12
13
# File 'app/controllers/config_manager/admins_controller.rb', line 11

def new
  @admin = Admin.new admin_params
end

#updateObject

POST /admin/:id/update



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/config_manager/admins_controller.rb', line 24

def update
  @admin = Admin.find(params[:id])
  if @admin.update_attributes admin_params
  	flash[:notice] = "Admin user #{@admin.email} successfully updated"
  else
  	render "edit"
  end
rescue ActiveRecord::RecordNotFound
  flash[:error] = "Admin with id=#{params[:id]} couldn't be found"
  redirect_to admins_path
end