Use a preinitializer to load the settings from application.yml so that they are available as early as possible. All settings can also be overridden using environment variables. The ad-hoc settins in environment.rb are then moved to this new system so we have one consistent location for settings.
15 lines
421 B
Ruby
15 lines
421 B
Ruby
class SpamObserver < ActiveRecord::Observer
|
|
observe User, DiaryEntry, DiaryComment
|
|
|
|
def after_save(record)
|
|
case
|
|
when record.is_a?(User): user = record
|
|
when record.is_a?(DiaryEntry): user = record.user
|
|
when record.is_a?(DiaryComment): user = record.user
|
|
end
|
|
|
|
if user.status == "active" and user.spam_score > SPAM_THRESHOLD
|
|
user.update_attributes(:status => "suspended")
|
|
end
|
|
end
|
|
end
|