Sha256: 71dd132876d8a4658f52c6a08f9c64f5fe8a9cac6ff1f4a117df581c4b040be1
Contents?: true
Size: 1.52 KB
Versions: 10
Compression:
Stored size: 1.52 KB
Contents
module ComfortableMexicanSofa::ControllerMethods 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 ComfortableMexicanSofa::MissingPage 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(options = {}, locals = {}, &block) if options.is_a?(Hash) && path = options.delete(:cms_page) @cms_site = Cms::Site.find_site(request.host.downcase, request.fullpath) @cms_page = @cms_site && @cms_site.pages.find_by_full_path(path) if @cms_page @cms_layout = @cms_page.layout cms_app_layout = @cms_layout.try(:app_layout) options[:layout] ||= cms_app_layout.blank?? nil : cms_app_layout options[:inline] = @cms_page.content super(options, locals, &block) else raise ComfortableMexicanSofa::MissingPage.new(path) end else super(options, locals, &block) end end end end ActionController::Base.send :include, ComfortableMexicanSofa::ControllerMethods
Version data entries
10 entries across 10 versions & 1 rubygems