Class: StaticContent::Content

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/static_content/content.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_slug(slug, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
# File 'app/models/static_content/content.rb', line 8

def self.from_slug(slug, options={})
  raise ArgumentError.new("You must provide a default text for a content.") if options[:default].nil?
  where(slug: slug).first_or_initialize.tap do |content|
    if content.new_record?
      content.text = options[:default]
      content.save
    end
  end
end

Instance Method Details

#parsed_textObject



18
19
20
# File 'app/models/static_content/content.rb', line 18

def parsed_text
  markdown.to_html.html_safe
end

#raw_textObject



22
23
24
# File 'app/models/static_content/content.rb', line 22

def raw_text
  text.html_safe
end