attr_accessible :body
after_initialize :set_defaults
+ after_save :spam_check
def body
RichText.new(read_attribute(:body_format), read_attribute(:body))
def set_defaults
self.body_format = "markdown" unless self.attribute_present?(:body_format)
end
+
+ def spam_check
+ user.spam_check
+ end
end
attr_accessible :title, :body, :language_code, :latitude, :longitude
after_initialize :set_defaults
+ after_save :spam_check
def body
RichText.new(read_attribute(:body_format), read_attribute(:body))
def set_defaults
self.body_format = "markdown" unless self.attribute_present?(:body_format)
end
+
+ def spam_check
+ user.spam_check
+ end
end
+++ /dev/null
-class SpamObserver < ActiveRecord::Observer
- observe User, DiaryEntry, DiaryComment
-
- def after_save(record)
- case
- when record.is_a?(User) then user = record
- when record.is_a?(DiaryEntry) then user = record.user
- when record.is_a?(DiaryComment) then user = record.user
- end
-
- if user.status == "active" and user.spam_score > SPAM_THRESHOLD
- user.update_column(:status, "suspended")
- end
- end
-end
after_initialize :set_defaults
before_save :encrypt_password
+ after_save :spam_check
has_attached_file :image,
:default_url => "/assets/:class/:attachment/:style.png",
return score.to_i
end
+ ##
+ # perform a spam check on a user
+ def spam_check
+ if status == "active" and spam_score > SPAM_THRESHOLD
+ update_column(:status, "suspended")
+ end
+ end
+
##
# return an oauth access token for a specified application
def access_token(application_key)
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
- # Activate observers that should always be running.
- unless STATUS == :database_offline
- config.active_record.observers = :spam_observer
- end
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'