Class: OCms::PagesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/o_cms/pages_controller.rb', line 20

def create
  @page = Page.new(page_params)

  if @page.save
    flash[:notice] = "Page was saved successfully."
    redirect_to edit_page_path(@page)
  else
    flash.now[:alert] = "Error creating page. Please try again."
    @pages = Page.all
    render :new
  end
end

#destroyObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/o_cms/pages_controller.rb', line 52

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

  if @page.destroy
    flash[:notice] = "\"#{@page.title}\" was deleted successfully."
    redirect_to action: :index
    @page.remove_subpage_relationships
  else
    flash.now[:alert] = "There was an error deleting the page."
    render :show
  end
end

#editObject



33
34
35
36
37
# File 'app/controllers/o_cms/pages_controller.rb', line 33

def edit
  @page = Page.find(params[:id])
  @pages = Page.all_except(@page)
  @templates = Template.all
end

#indexObject



6
7
8
# File 'app/controllers/o_cms/pages_controller.rb', line 6

def index
  @pages = Page.page_parents
end

#newObject



14
15
16
17
18
# File 'app/controllers/o_cms/pages_controller.rb', line 14

def new
  @page = Page.new
  @pages = Page.all
  @templates = Template.all
end

#showObject



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

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

#updateObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/o_cms/pages_controller.rb', line 39

def update
  @page = Page.find(params[:id])
  @page.assign_attributes(page_params)

  if @page.save
    flash[:notice] = "Page was updated successfully."
    redirect_to edit_page_path(@page)
  else
    flash.now[:alert] = "Error saving page. Please try again."
    render :edit
  end
end