Class: Admin::PagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin/pages_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


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

def create
  @page = Page.new(params[:page].permit!)

  if @page.save
    redirect_to(admin_pages_path, notice: 'Page was successfully created.')
  else
    render action: 'new'
  end
end

#destroyObject


44
45
46
47
48
49
# File 'app/controllers/admin/pages_controller.rb', line 44

def destroy
  @page = Page.unscoped.find_by_slug(params[:id])
  @page.destroy

  redirect_to(admin_pages_path)
end

#editObject


15
16
17
# File 'app/controllers/admin/pages_controller.rb', line 15

def edit
  @page = Page.unscoped.find_by_slug(params[:id])
end

#indexObject


3
4
5
# File 'app/controllers/admin/pages_controller.rb', line 3

def index
  @pages = Page.unscoped.order(id: :desc).paginate page: params[:page], per_page: 30
end

#newObject


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

def new
  @page = Page.new
end

#showObject


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

def show
  @page = Page.unscoped.find_by_slug(params[:id])
end

#updateObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/admin/pages_controller.rb', line 29

def update
  @page = Page.unscoped.find_by_slug(params[:id])
  @page.title = params[:page][:title]
  @page.body = params[:page][:body]
  @page.slug = params[:page][:slug]
  @page.locked = params[:page][:locked]
  @page.user_id = current_user.id

  if @page.save
    redirect_to(admin_pages_path, notice: 'Page was successfully updated.')
  else
    render action: 'edit'
  end
end