Class: Content

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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

Raises:

  • (ArgumentError)


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

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

Instance Method Details

#parsed_textObject



20
21
22
# File 'app/models/content.rb', line 20

def parsed_text
  markdown.to_html.html_safe
end

#raw_textObject



24
25
26
# File 'app/models/content.rb', line 24

def raw_text
  text.html_safe
end