Class: DynamicContent::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DynamicContent::Page
- Defined in:
- app/models/dynamic_content/page.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.cached_for(page) ⇒ Object
40 41 42 |
# File 'app/models/dynamic_content/page.rb', line 40 def self.cached_for page Rails.cache.fetch([name, ("cached_page_#{page}".downcase)]) { Page.load(page) } end |
.load(page) ⇒ Object
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 'app/models/dynamic_content/page.rb', line 14 def self.load page current = self.includes(:sections).find_by_slug(page) return {} if current.nil? results = { id: current.id, title: current.title, keywords: current.keywords.try(:join, ', '), description: current.description } sections_content = current.sections#.where(on_application: false) sections_content = sections_content + Section.where(on_application: true) if page == 'application' sections_content.each do |section| results[section.slug.to_sym] = { name: section.name } section.contents.each do |content| results[section.slug.to_sym][content.slug.to_sym] = content.get_content end end return results end |
Instance Method Details
#flush_cache ⇒ Object
44 45 46 47 |
# File 'app/models/dynamic_content/page.rb', line 44 def flush_cache Rails.cache.delete([self.class.name, ("cached_page_#{self.slug}".downcase)]) Rails.cache.delete([self.class.name, ("cached_page_application".downcase)]) end |