Class: Cms::PagesController
Constant Summary
collapse
- SEARCH_LIMIT =
40
Instance Method Summary
collapse
#index
#authenticate_user
#authorize_role, #current_user
Instance Method Details
#create ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'app/controllers/cms/pages_controller.rb', line 12
def create
@page = @context.pages.build(params[:cms_page])
if @page.save
flash[:notice] = t('pages.flash.created')
redirect_to cms_root_path
else
render :action => 'new'
end
end
|
#destroy ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
|
# File 'app/controllers/cms/pages_controller.rb', line 47
def destroy
@page = @context.pages.find(params[:id])
@page.destroy
flash[:notice] = t('pages.flash.deleted')
respond_to do |format|
format.html { redirect_to cms_root_path }
format.js
end
end
|
#edit ⇒ Object
22
23
24
|
# File 'app/controllers/cms/pages_controller.rb', line 22
def edit
@page = @context.pages.find params[:id]
end
|
#load ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/controllers/cms/pages_controller.rb', line 59
def load
flash.discard
params[:url] ||= ''
path = '/'+params[:url]
url_parts = params[:url].split('/')
@page = if path == '/'
@context.pages.root || @context.pages.published.first
else
@context.pages.published.first(:conditions => {:slug => path}) || @context.pages.published.first(:conditions => {:name => url_parts.first}) || @context.pages.published.first(:conditions => {:slug => wildcard_path})
end
if @page
response.content_type = @page.content_type
begin
render :text => @page.rendered_content(self)
rescue Liquid::SyntaxError, Liquid::ArgumentError, ArgumentError
render :text => $!.message
rescue Exception => e
f = e.class.new(e.message + "\n\n" + @page.content)
f.set_backtrace e.backtrace
raise f
end
else
raise ActionController::RoutingError, "No route matches #{params.inspect}"
end
end
|
#new ⇒ Object
8
9
10
|
# File 'app/controllers/cms/pages_controller.rb', line 8
def new
@page = Cms::Page.new
end
|
#page_asset ⇒ Object
for loading stylesheets or javascript content
93
94
95
96
97
98
99
100
101
102
|
# File 'app/controllers/cms/pages_controller.rb', line 93
def page_asset
@page = @context.pages.find_by_name [params[:id], params[:format]].compact.join('.')
if @page
response.content_type = @page.content_type
render :text => @page.rendered_content(self)
else
render :nothing => true, :status => 404
end
end
|
#search ⇒ Object
104
105
106
107
108
|
# File 'app/controllers/cms/pages_controller.rb', line 104
def search
@search_term = (params[:search] || '').strip
@pages = @search_term.blank? ? [] : @context.pages.all(:conditions => ["upper(content) like ?", "%#{@search_term.upcase}%"])
end
|
#update ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/cms/pages_controller.rb', line 26
def update
@page = @context.pages.find params[:id]
if @page.update_attributes(params[:cms_page])
respond_to do |format|
format.html {
redirect_to edit_cms_page_path(@page), :notice => t('pages.flash.updated')
}
format.js {
flash.now[:notice] = t('pages.flash.updated')
}
end
else
respond_to do |format|
format.html {
render :action => 'edit'
}
format.js
end
end
end
|