Class: PagesController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#req, #res

Instance Method Summary collapse

Methods inherited from ApplicationController

#csrf_token, #initialize, #log_activity, #params, #redirect_to, #render, #render_json, #session, #validate!

Constructor Details

This class inherits a constructor from ApplicationController

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/pages_controller.rb', line 14

def create
  data = params['page']
  data['is_active'] = boolean_param(data['is_active'])
  data['is_nav'] = boolean_param(data['is_nav'])
  @page = Page.new(data)
  if @page.save
    log_activity("Created page: #{@page.title}", @page, "Slug: #{@page.slug}, Nav: #{@page.is_nav}")
    redirect_to '/dashboard/pages'
  else
    render 'cms/pages_form'
  end
end

#destroyObject



45
46
47
48
49
50
51
52
# File 'app/controllers/pages_controller.rb', line 45

def destroy
  @page = Page[params['id']]
  title = @page.title
  delete_all_images_from_content(@page.content) if @page.respond_to?(:content)
  @page.destroy
  log_activity("Deleted page: #{title}")
  redirect_to '/dashboard/pages'
end

#editObject



27
28
29
30
# File 'app/controllers/pages_controller.rb', line 27

def edit
  @page = Page[params['id']]
  render 'cms/pages_form'
end

#indexObject



4
5
6
7
# File 'app/controllers/pages_controller.rb', line 4

def index
  @pages = Page.all
  render 'cms/pages_index'
end

#newObject



9
10
11
12
# File 'app/controllers/pages_controller.rb', line 9

def new
  @page = Page.new
  render 'cms/pages_form'
end

#updateObject



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

def update
  @page = Page[params['id']]
  data = params['page']
  data['is_active'] = boolean_param(data['is_active'])
  data['is_nav'] = boolean_param(data['is_nav'])
  if @page.update(data)
    log_activity("Updated page: #{@page.title}", @page, "New Data: #{data.reject{|k| k == 'content'}.to_json}")
    redirect_to '/dashboard/pages'
  else
    render 'cms/pages_form'
  end
end