Class: Blog
- Inherits:
-
Object
- Object
- Blog
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/blog.rb
Instance Method Summary collapse
-
#copy_posts ⇒ Object
Migrates this blog’s embedded posts to referenced ones.
-
#feed ⇒ String
Returns this blog’s RSS feed.
-
#feed_address ⇒ Object
deprecated
Deprecated.
Please use #feed instead
-
#humanize_path ⇒ Object
deprecated
Deprecated.
Please use #path instead
-
#path ⇒ String
Returns this blog’s path.
-
#path_ts ⇒ String
Returns this blog’s path with a trailing slash.
-
#posts_by_month ⇒ Hash
Returns this blog’s posts keyed by publication date.
-
#search(keyword) ⇒ Array
Returns published posts matching the specified keyword.
Instance Method Details
#copy_posts ⇒ Object
Migrates this blog’s embedded posts to referenced ones.
28 29 30 31 32 33 34 35 36 |
# File 'app/models/blog.rb', line 28 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.blog_category_ids = post.blog_category_ids p.save self.post2s << p end end |
#feed ⇒ String
Returns this blog’s RSS feed.
41 42 43 |
# File 'app/models/blog.rb', line 41 def feed "#{self.path}/feed.rss" end |
#feed_address ⇒ Object
Deprecated.
Please use #feed instead
46 47 48 49 |
# File 'app/models/blog.rb', line 46 def feed_address warn "[DEPRECATION] `feed_address` is deprecated. Please use `feed` instead." self.feed end |
#humanize_path ⇒ Object
Deprecated.
Please use #path instead
52 53 54 55 |
# File 'app/models/blog.rb', line 52 def humanize_path warn "[DEPRECATION] `humanize_path` is deprecated. Please use `path` instead." self.path end |
#path ⇒ String
Returns this blog’s path.
60 61 62 |
# File 'app/models/blog.rb', line 60 def path "/#{self.slug}" end |
#path_ts ⇒ String
Returns this blog’s path with a trailing slash.
67 68 69 |
# File 'app/models/blog.rb', line 67 def path_ts "#{self.path}/" end |
#posts_by_month ⇒ Hash
Returns this blog’s posts keyed by publication date.
74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/blog.rb', line 74 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) ⇒ Array
Returns published posts matching the specified keyword.
90 91 92 |
# File 'app/models/blog.rb', line 90 def search(keyword) self.posts.published.where :content => /#{keyword}/i end |