Class: Decidim::ContextualHelpSection

Inherits:
ApplicationRecord show all
Includes:
TranslatableResource
Defined in:
app/models/decidim/contextual_help_section.rb

Class Method Summary collapse

Class Method Details

.find_content(organization, id) ⇒ Object

Public: Finds content given an id

organization - The Organization to scope the content to id - A String with the id

Returns a Hash with the localized content



19
20
21
# File 'app/models/decidim/contextual_help_section.rb', line 19

def self.find_content(organization, id)
  find_by(organization: organization, section_id: id).try(:content) || {}
end

.set_content(organization, id, content) ⇒ Object

Public: Stores the content.

organization - The Organization to scope the content to id - A String with the id content - A Hash with the content to store

Returns a Hash with the localized content



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/decidim/contextual_help_section.rb', line 30

def self.set_content(organization, id, content)
  item = find_or_initialize_by(
    organization: organization,
    section_id: id
  )

  if content.present? && content.values.any?(&:present?)
    item.update!(content: content)
  else
    item.destroy!
  end

  content
end