Module: ComfortableMexicanSofa::ControllerMethods
- Defined in:
- lib/comfortable_mexican_sofa/controller_methods.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#render(options = {}, locals = {}, &block) ⇒ Object
Now you can render cms_page simply by calling: render :cms_page => ‘/path/to/page’ This way application controllers can use CMS content while populating instance variables that can be used in partials (that are included by by the cms page and/or layout).
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/comfortable_mexican_sofa/controller_methods.rb', line 3 def self.included(base) # If application controller doesn't have template associated with it # CMS will attempt to find one. This is so you don't have to explicitly # call render :cms_page => '/something' base.rescue_from 'ActionView::MissingTemplate' do |e| begin render :cms_page => request.path rescue ActionView::MissingTemplate raise e end end # Now you can render cms_page simply by calling: # render :cms_page => '/path/to/page' # This way application controllers can use CMS content while populating # instance variables that can be used in partials (that are included by # by the cms page and/or layout) def render( = {}, locals = {}, &block) if .is_a?(Hash) && path = .delete(:cms_page) site = Cms::Site.find_by_hostname(request.host.downcase) page = site && site.pages.find_by_full_path(path) if page cms_app_layout = page.layout.try(:app_layout) [:layout] ||= cms_app_layout.blank?? nil : cms_app_layout [:inline] = page.content @cms_page = page super(, locals, &block) else raise ActionView::MissingTemplate.new([path], path, "CMS page not found", nil) end else super(, locals, &block) end end end |
Instance Method Details
#render(options = {}, locals = {}, &block) ⇒ Object
Now you can render cms_page simply by calling:
render :cms_page => '/path/to/page'
This way application controllers can use CMS content while populating instance variables that can be used in partials (that are included by by the cms page and/or layout)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/comfortable_mexican_sofa/controller_methods.rb', line 21 def render( = {}, locals = {}, &block) if .is_a?(Hash) && path = .delete(:cms_page) site = Cms::Site.find_by_hostname(request.host.downcase) page = site && site.pages.find_by_full_path(path) if page cms_app_layout = page.layout.try(:app_layout) [:layout] ||= cms_app_layout.blank?? nil : cms_app_layout [:inline] = page.content @cms_page = page super(, locals, &block) else raise ActionView::MissingTemplate.new([path], path, "CMS page not found", nil) end else super(, locals, &block) end end |