Permalink
Browse files

added publish date support. fixes bug where categories were showing p…

…osts that were technically supposed to be hidden from the end user
  • Loading branch information...
1 parent 18b2db5 commit f036f2a46f5c085505aff507f54518df8e283069 @djones djones committed Sep 21, 2010
@@ -8,5 +8,16 @@ class BlogCategory < ActiveRecord::Base
validates_uniqueness_of :title
has_friendly_id :title, :use_slug => true
-
+
+ # this might be able to be optimised a little more
+ def post_count
+ count = 0
+
+ self.posts.each do |p|
+ count += 1 if p.live?
+ end
+
+ count
+ end
+
end
View
@@ -13,11 +13,15 @@ class BlogPost < ActiveRecord::Base
default_scope :order => "created_at DESC"
if Rails.version < '3.0.0'
- named_scope :live, :conditions => {:draft => false}
+ named_scope :live, lambda { {:conditions => ["published_at < ? and draft = ?", Time.now, false]} }
else
- scope :live, :conditions => {:draft => false}
+ scope :live, lambda { where( "published_at < ? and draft = ?", Time.now, false) }
end
-
+
+ def live?
+ !draft and published_at <= Time.now
+ end
+
def category_ids=(ids)
self.categories = ids.reject{|id| id.blank?}.collect {|c_id|
BlogCategory.find(c_id.to_i) rescue nil
@@ -44,6 +44,8 @@
</li>
<% end %>
</ul>
+ <h3><%= t('admin.blog.posts.form.published_at') %></h3>
+ <%= f.datetime_select :published_at %>
</div>
<div class='hemisquare right_side'>
</div>
@@ -2,7 +2,7 @@
<ul id='categories'>
<% @blog_categories.each do |category| %>
<li<%= " class='selected'" if @category.present? and @category.id == category.id %>>
- <%= link_to "#{category.title} (#{category.posts.count})", blog_category_url(category) %>
+ <%= link_to "#{category.title} (#{category.post_count})", blog_category_url(category) %>
</li>
<% end %>
</ul>
@@ -1,22 +1,24 @@
-<li>
- <h2><%= link_to post.title, blog_post_url(post) %></h2>
- <p class='posted_at'>
- <%= t('blog.shared.posts.created_at', :when => post.created_at.strftime('%d %B %Y')) %>
- </p>
- <div clas='clearfix'>
- <%= truncate(post.body,
- :length => RefinerySetting.find_or_set(:blog_post_teaser_length, 250),
- :preserve_html_tags => true) %>
- </div>
- <p>
- <%= link_to t('blog.shared.posts.read_more'), blog_post_url(post) %>
+<% if post.live? %>
+ <li>
+ <h2><%= link_to post.title, blog_post_url(post) %></h2>
+ <p class='posted_at'>
+ <%= t('blog.shared.posts.created_at', :when => post.published_at.strftime('%d %B %Y')) %>
+ </p>
+ <div clas='clearfix'>
+ <%= truncate(post.body,
+ :length => RefinerySetting.find_or_set(:blog_post_teaser_length, 250),
+ :preserve_html_tags => true) %>
+ </div>
+ <p>
+ <%= link_to t('blog.shared.posts.read_more'), blog_post_url(post) %>
- <span class='comment_count'>
- <% if post.comments.any? %>
- (<%= pluralize(post.comments.count, t('blog.shared.comments.singular')) %>)
- <% else %>
- (<%= t('blog.shared.comments.none') %>)
- <% end %>
- </span>
- </p>
-</li>
+ <span class='comment_count'>
+ <% if post.comments.any? %>
+ (<%= pluralize(post.comments.count, t('blog.shared.comments.singular')) %>)
+ <% else %>
+ (<%= t('blog.shared.comments.none') %>)
+ <% end %>
+ </span>
+ </p>
+ </li>
+<% end %>
View
@@ -37,6 +37,7 @@ en:
advanced_options: Advanced Options
toggle_advanced_options: Click to access meta tag settings and menu options
save_as_draft: Save as Draft
+ published_at: Publish Date
index:
no_items_yet: 'There are no Blog Posts yet. Click "{{create}}" to add your first blog post.'
post:
@@ -38,6 +38,7 @@ def manifest
Rails::Generator::GeneratedAttribute.new('title', 'string'),
Rails::Generator::GeneratedAttribute.new('body', 'text'),
Rails::Generator::GeneratedAttribute.new('draft', 'boolean')
+ Rails::Generator::GeneratedAttribute.new('published_at', 'datetime')
], :id => true
},{
:table_name => 'blog_comments',

0 comments on commit f036f2a

Please sign in to comment.