From f221da62cde073059424eddaa1f7a52ed67de848 Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Mon, 21 Feb 2011 13:16:42 +1300 Subject: Added settings click-button functionality for toggling comments being enabled, with translations. --- app/models/blog_comment.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index 015b96d..13aceb1 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -13,7 +13,7 @@ class BlogComment < ActiveRecord::Base alias_attribute :message, :body validates :name, :message, :presence => true - validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i } + validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i } scope :unmoderated, :conditions => {:state => nil} scope :approved, :conditions => {:state => 'approved'} @@ -39,6 +39,13 @@ class BlogComment < ActiveRecord::Base self.state.nil? end + def self.toggle! + currently = RefinerySetting.find_or_set(:comments_allowed, true, { + :scoping => 'blog' + }) + RefinerySetting.set(:comments_allowed, {:value => !currently, :scoping => 'blog'}) + end + before_create do |comment| unless BlogComment::Moderation.enabled? comment.state = comment.ham? ? 'approved' : 'rejected' -- cgit v1.2.3