Class: Cmsimple::PagesController

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/cmsimple/pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#check_for_redirectObject



79
80
81
82
83
84
85
86
# File 'app/controllers/cmsimple/pages_controller.rb', line 79

def check_for_redirect
  return true if params[:id].present?
  if current_path.redirect?
    path = current_path.destination.uri
    path = "/editor#{path}" if action_name == 'editor'
    redirect_to path, status: 301
  end
end

#createObject



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

def create
  params[:page].delete :id if params[:page] && params[:page].key?(:id)
  @page = Page.new(params[:page])
  if @page.save
    respond_with(@page)
  else
    render :new, layout: false, status: 422
  end
end

#current_pageObject



75
76
77
# File 'app/controllers/cmsimple/pages_controller.rb', line 75

def current_page
  @page ||= current_path.destination
end

#current_pathObject

helpers



71
72
73
# File 'app/controllers/cmsimple/pages_controller.rb', line 71

def current_path
  @path ||= Path.from_request!(request)
end

#destroyObject



62
63
64
65
66
67
68
# File 'app/controllers/cmsimple/pages_controller.rb', line 62

def destroy
  @page = Page.find(params[:id])
  @page.destroy
  respond_with(@page) do |format|
    format.html{ redirect_to '/editor' }
  end
end

#editObject



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

def edit
  @page = Page.find(params[:id])
  render :edit, :layout => false
end

#editorObject



23
24
25
# File 'app/controllers/cmsimple/pages_controller.rb', line 23

def editor
  render :nothing => true, :layout => 'editor'
end

#indexObject



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

def index
  @pages = Page.all
  respond_with @pages
end

#newObject



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

def new
  @page = Page.new
  render :new, :layout => false
end

#publishObject



37
38
39
40
# File 'app/controllers/cmsimple/pages_controller.rb', line 37

def publish
  @page = Page.find(params[:id])
  render :publish, :layout => false
end

#showObject



13
14
15
16
# File 'app/controllers/cmsimple/pages_controller.rb', line 13

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

#updateObject



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

def update
  @page = Page.find(params[:id])
  params[:page].delete :id if params[:page] && params[:page].key?(:id)
  if @page.update_attributes(params[:page])
    respond_with(@page)
  else
    render :edit, layout: false, status: 422
  end
end

#update_contentObject



18
19
20
21
# File 'app/controllers/cmsimple/pages_controller.rb', line 18

def update_content
  current_page.update_content(params[:content])
  respond_with @page, :location => @page.uri
end