Class: Blog
- Inherits:
-
Object
- Object
- Blog
- Includes:
- BlogLogic::Base, Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/blog.rb
Instance Attribute Summary collapse
-
#desired_slug ⇒ Object
Behavior =======================================================================================.
Instance Method Summary collapse
-
#copy_posts ⇒ Object
Instance methods ===============================================================================.
- #feed_address ⇒ Object
- #humanize_path ⇒ Object
- #path ⇒ Object
- #posts_by_month ⇒ Object
- #search(keyword) ⇒ Object
Methods included from BlogLogic::Base
Instance Attribute Details
#desired_slug ⇒ Object
Behavior =======================================================================================
22 23 24 |
# File 'app/models/blog.rb', line 22 def desired_slug @desired_slug end |
Instance Method Details
#copy_posts ⇒ Object
Instance methods ===============================================================================
29 30 31 32 33 34 35 36 |
# File 'app/models/blog.rb', line 29 def copy_posts self.posts.each do |post| p = Post2.create :slug => post.slug, :content => post.content, :tags => post., :author => post., :published_at => post.published_at, :state => post.state, :publication_date => post.publication_date, :summary => post.summary p.title = post.title p.save self.post2s << p end end |
#feed_address ⇒ Object
38 39 40 |
# File 'app/models/blog.rb', line 38 def feed_address "/#{self.slug}/feed.rss" end |
#humanize_path ⇒ Object
42 43 44 |
# File 'app/models/blog.rb', line 42 def humanize_path self.path end |
#path ⇒ Object
46 47 48 |
# File 'app/models/blog.rb', line 46 def path "/#{self.slug}/".gsub(/\/\//,'/').gsub(/\/\//,'/') end |
#posts_by_month ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/blog.rb', line 50 def posts_by_month dates = {} self.posts.published.each do |p| date = p.publication_date.to_s(:year_month) dates[date] ||= {} dates[date][:full_date] ||= p.publication_date.to_s(:month_year) dates[date][:posts] ||= [] dates[date][:posts] << p end dates end |
#search(keyword) ⇒ Object
62 63 64 |
# File 'app/models/blog.rb', line 62 def search(keyword) self.posts.published.where(:content => /#{keyword}/i) end |