Skip to content
Browse files

For the installation instructions to work, we need to check whether t…

…he table exists before using acts_as_taggalbe_on.
  • Loading branch information...
1 parent d1406b1 commit d1b2b43a0c25dff66fba4de0278beadf696964e6 @parndt committed
Showing with 11 additions and 11 deletions.
  1. +11 −11 app/models/blog.rb
View
22 app/models/blog.rb
@@ -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],
@@ -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
@@ -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
@@ -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.
Something went wrong with that request. Please try again.