Class: Newsly::Template

Inherits:
LiquidModel
  • Object
show all
Defined in:
app/models/newsly/template.rb

Instance Method Summary collapse

Methods inherited from LiquidModel

#after_validation, #body=, #render

Instance Method Details

#body_must_follow_validation_rulesObject



26
27
28
29
30
31
32
33
34
35
# File 'app/models/newsly/template.rb', line 26

def body_must_follow_validation_rules
  failed = []
  unless validation_rules.blank?
    validation_rules.split(',').each do |rule|
      rule = rule.strip
      failed.push(rule) unless body=~ /{{rule}}/
    end
    errors.add(:body, "#{failed.to_sentence} is required") if failed.length > 0
  end
end

#publishObject

Takes a draft and copies information to the original



18
19
20
21
22
23
24
# File 'app/models/newsly/template.rb', line 18

def publish
  original = Newsly::Template.find(self.parent_id)
  original.subject= self.subject
  original.body= self.body
  original.save
  original
end