Class: CmsContentitem

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
RankedModel
Defined in:
app/models/cms_contentitem.rb

Overview

Note: fragment caching is used during rendering. The cache key is based on both the model and the current locale (because each model supports multiple translations). The cache will be busted automatically since the updated_at attribute will be updated on save.


Defined Under Namespace

Classes: Translation

Constant Summary collapse

CONTENT_TYPES =

— content types supported

[ 'Markdown', 'Textile', 'HTML' ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#original_updated_onObject




38
39
40
# File 'app/models/cms_contentitem.rb', line 38

def original_updated_on
  @original_updated_on || self.updated_on.to_f
end

Instance Method Details

#deep_clone(new_cms_page_id) ⇒ Object




66
67
68
69
70
71
72
73
74
# File 'app/models/cms_contentitem.rb', line 66

def deep_clone(new_cms_page_id)
  new_cms_contentitem                  = self.clone
  new_cms_contentitem.cms_page_id      = new_cms_page_id

  DmCore::Language.language_array.each do |locale|
    eval("new_cms_contentitem.content_#{locale[:lang]}     = content_#{locale[:lang]} unless content_#{locale[:lang]}.nil?")
  end
  new_cms_contentitem.save
end

#to_liquidObject

Generate any data to pass when rendering with Liquid




61
62
63
# File 'app/models/cms_contentitem.rb', line 61

def to_liquid
  cms_page.to_liquid
end

#validate_conflictObject

Try to see if the record has been changed by someone while being edited by someone else. If original_updated_on is not set, then don’t check - allows acts_as_list methods to update without causing a problem.

todo

still needed since we don’t use acts_as_list anymore?




48
49
50
51
52
53
54
55
56
57
# File 'app/models/cms_contentitem.rb', line 48

def validate_conflict
  if @conflict || (!@original_updated_on.nil? && self.updated_on.to_f > @original_updated_on.to_f)
    @conflict             = true
    @original_updated_on  = nil
    errors.add :base, "This record was changed while you were editing."
    changes.each do |attribute, values|
      errors.add attribute, "was #{values.first}"
    end
  end
end