Module: Cms::Content

Defined in:
app/models/cms/content.rb

Overview

An API for interacting with the Content API of BrowserCMS.

Class Method Summary collapse

Class Method Details

.find(content_type, id) ⇒ ContentBlock

Find a single content item. example:

Cms::Content.find("html_block", 12) # Finds a Cms::HtmlBlock with an id of 12.

Parameters:

  • content_name (String)

    The name of the content type to find.

  • id (Integer)

    The id of the content.

Returns:

  • (ContentBlock)

    A single content block or page



12
13
14
15
16
17
18
# File 'app/models/cms/content.rb', line 12

def self.find(content_type, id)
  if content_type == "page"
    return Cms::Page.find(id)
  end
  type = ContentType.find_by_key(content_type)
  type.model_class.find(id)
end

.find_draft(content_type, id) ⇒ ContentBlock

Find the latest draft for a single content item. example:

Cms::Content.find("html_block", 12) # Finds a Cms::HtmlBlock with an id of 12.

Parameters:

  • content_name (String)

    The name of the content type to find.

  • id (Integer)

    The id of the content.

Returns:

  • (ContentBlock)

    A single content block or page



27
28
29
# File 'app/models/cms/content.rb', line 27

def self.find_draft(content_type, id)
  find(content_type, id).as_of_draft_version
end