Skip to content

Commit

Permalink
For the installation instructions to work, we need to check whether t…
Browse files Browse the repository at this point in the history
…he table exists before using acts_as_taggalbe_on.
  • Loading branch information
parndt committed Jul 23, 2010
1 parent d1406b1 commit d1b2b43
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions app/models/blog.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Blog < ActiveRecord::Base
acts_as_taggable_on :categories, :tags, :authors

acts_as_taggable_on :categories, :tags, :authors if self.table_exists?

has_many :comments

named_scope :published, lambda {{:conditions => ["publishing_date < '#{Time.now.to_formatted_s(:db)}' and draft != ?", true],
Expand All @@ -17,9 +17,9 @@ class Blog < ActiveRecord::Base
validates_format_of :permalink, :with => /^(([-_]|[a-z]|\d){1,100})$/, :message => " is invalid, only lowercase alphanumeric character and _-"
validates_length_of :permalink, :within => 4..99
validates_length_of :title, :within => 2..95

NUM_RECENT_POSTS = 5

def before_validation
self.permalink = title.parameterize if permalink.blank?
end
Expand All @@ -29,15 +29,15 @@ def published?
# the publishing date is before now and it is not a draft blog post.
publishing_date <= Time.now && !draft
end

def approved_comment_count
comments.approved.size
end

def self.grouped_by_date
all.group_by { |blog| blog.publishing_date.to_date }.sort {|a,b| b[0] <=> a[0]}
end

def self.tags
Blog.published.tag_counts.collect(&:name)
end
Expand All @@ -49,15 +49,15 @@ def self.categories
def self.authors
Blog.published.author_counts.collect(&:name)
end

def self.recent_posts
Blog.published.first(NUM_RECENT_POSTS)
end

def recent_posts
recent_posts = Blog.published(:limit => (NUM_RECENT_POSTS+1))
recent_posts.delete(self)
recent_posts.first(NUM_RECENT_POSTS)
end

end

0 comments on commit d1b2b43

Please sign in to comment.