diff options
author | Philip Arndt <parndt@gmail.com> | 2010-09-02 17:49:11 +1200 |
---|---|---|
committer | Philip Arndt <parndt@gmail.com> | 2010-09-02 17:49:11 +1200 |
commit | 5c71c0aaa5c96683b56d2d8af0dfdac8424e41d2 (patch) | |
tree | e0437a22051a2128ac0e9dcf08b3a2d16c73b4e0 /app/models | |
parent | 4d1e364085c0de27d3ca58cc90eba9036744fc79 (diff) | |
download | refinerycms-blog-5c71c0aaa5c96683b56d2d8af0dfdac8424e41d2.tar.gz refinerycms-blog-5c71c0aaa5c96683b56d2d8af0dfdac8424e41d2.tar.bz2 refinerycms-blog-5c71c0aaa5c96683b56d2d8af0dfdac8424e41d2.zip |
Comment moderation now working in the backend. Of course it still happens automatically if the blog isn't moderated based on whether it's spam or not.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/blog_comment.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index c115aef..4c7be77 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -4,7 +4,7 @@ class BlogComment < ActiveRecord::Base :email_field => :email, :message_field => :body - belongs_to :post, :class_name => 'BlogPost' + belongs_to :post, :class_name => 'BlogPost', :foreign_key => 'blog_post_id' acts_as_indexed :fields => [:name, :email, :message] @@ -18,6 +18,26 @@ class BlogComment < ActiveRecord::Base named_scope :approved, :conditions => {:state => 'approved'} named_scope :rejected, :conditions => {:state => 'rejected'} + def approve! + self.update_attribute(:state, 'approved') + end + + def reject! + self.update_attribute(:state, 'rejected') + end + + def rejected? + self.state == 'rejected' + end + + def approved? + self.state == 'approved' + end + + def unmoderated? + self.state.nil? + end + before_create do |comment| unless BlogComment::Moderation.enabled? comment.state = comment.spam? ? 'rejected' : 'approved' |