Class: Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Post
- Defined in:
- app/models/post.rb
Constant Summary collapse
- SECTION_DELIMITER =
'<!--ej:section-->'
Instance Method Summary collapse
-
#before_save ⇒ Object
The updated_on time stamp is always updated to now.
- #sections ⇒ Object
- #updated? ⇒ Boolean
Instance Method Details
#before_save ⇒ Object
The updated_on time stamp is always updated to now.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/post.rb', line 12 def before_save self.subject = CGI.escapeElement(self.subject, 'script') self.body = CGI.escapeElement(self.body, 'script') @sections = self.body.split(/^----\s*$/).map! do |section| RedCloth.new(section).to_html.gsub(/\t/, '') end self.rendered = @sections.join(SECTION_DELIMITER) self.slug = self.subject.downcase.gsub(/[^a-z0-9 _-]+/, '').gsub(/ +/, '-').gsub(/-+/, '-') end |
#sections ⇒ Object
28 29 30 31 |
# File 'app/models/post.rb', line 28 def sections return @sections.dup if @sections (@sections = self.rendered.split(SECTION_DELIMITER)).dup end |
#updated? ⇒ Boolean
24 25 26 |
# File 'app/models/post.rb', line 24 def updated? self.created_at.strftime('%Y%m%d%H%M%S') != self.updated_at.strftime('%Y%m%d%H%M%S') end |