Method: ComfortableMexicanSofa::RenderMethods#render

Defined in:
lib/comfortable_mexican_sofa/render_methods.rb

#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)

Or how about not worrying about setting up CMS pages and rendering application view using a CMS layout?

render cms_layout: 'layout_slug', cms_fragments: {
  fragment_identifier_a: 'content text',
  fragment_identifier_b: {template: 'path/to/template' },
  fragment_identifier_c: {partial:  'path/to/partial' }
}

This way you are populating page block content and rendering an instantialized CMS page.

Site is loaded automatically based on the request. However you can force it by passing :cms_site parameter with site’s slug. For example:

render cms_page: '/path/to/page', cms_site: 'default'


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/comfortable_mexican_sofa/render_methods.rb', line 39

def render(options = {}, locals = {}, &block)
  return super unless options.is_a?(Hash)

  if (site_identifier = options.delete(:cms_site))
    unless (@cms_site = Comfy::Cms::Site.find_by_identifier(site_identifier))
      raise ComfortableMexicanSofa::MissingSite, site_identifier
    end
  end

  if (page_path = options.delete(:cms_page)) || (layout_identifier = options.delete(:cms_layout))
    unless @cms_site ||= Comfy::Cms::Site.find_site(request.host_with_port.downcase, request.fullpath)
      raise ComfortableMexicanSofa::MissingSite, "#{request.host.downcase}/#{request.fullpath}"
    end
  end

  if page_path
    render_cms_page(page_path, options, locals, &block)
  elsif layout_identifier
    render_cms_layout(layout_identifier, options, locals, &block)
  else
    super
  end
end