Class: OCms::PagesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

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



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

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



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

def edit
  @page = Page.find(params[:id])
  @pages = Page.all_except(@page)
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
# File 'app/controllers/o_cms/pages_controller.rb', line 14

def new
  @page = Page.new
  @pages = Page.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



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

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