Class: Caboose::Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Caboose::Post
- Defined in:
- app/models/caboose/post.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.slug(str) ⇒ Object
40 41 42 |
# File 'app/models/caboose/post.rb', line 40 def self.slug(str) return str.downcase.gsub(' ', '-').gsub(/[^\w-]/, '') end |
.uri(post) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'app/models/caboose/post.rb', line 44 def self.uri(post) str = "/posts/#x{post.created_at.strftime('%Y/%m/%d')}/#{post.slug}" i = 2 while Caboose::Post.where("site_id = ? and id <> ? and uri = ?", post.site_id, post.id, str).exists? str = "/posts/#{post.created_at.strftime('%Y/%m/%d')}/#{post.slug}-#{i}" i = i + 1 end return str end |
Instance Method Details
#block ⇒ Object
32 33 34 |
# File 'app/models/caboose/post.rb', line 32 def block Caboose::Block.where("post_id = ? and parent_id is null", self.id).first end |
#set_slug_and_uri(str) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/caboose/post.rb', line 54 def set_slug_and_uri(str) d = self.created_at.strftime('%Y/%m/%d') s = Caboose::Post.slug(str) new_slug = "#{s}" new_uri = "/posts/#{d}/#{new_slug}" i = 2 while Caboose::Post.where("site_id = ? and id <> ? and uri = ?", self.site_id, self.id, new_uri).exists? new_slug = "#{s}-#{i}" new_uri = "/posts/#{d}/#{new_slug}" i = i + 1 end self.slug = new_slug self.uri = new_uri self.save end |