environment_notification.rb
885 Bytes
class EnvironmentNotificationPlugin::EnvironmentNotification < ActiveRecord::Base
self.table_name = "environment_notifications"
TYPE_LIST = [
"EnvironmentNotificationPlugin::WarningNotification",
"EnvironmentNotificationPlugin::SuccessNotification",
"EnvironmentNotificationPlugin::InformationNotification",
"EnvironmentNotificationPlugin::DangerNotification"
]
attr_accessible :message, :environment_id, :active, :type, :display_only_in_homepage, :display_to_all_users
has_many :environment_notifications_users
has_many :users, :through => :environment_notifications_users
validates_presence_of :message
validates_presence_of :environment_id
validate :notification_type_must_be_in_type_list
def notification_type_must_be_in_type_list
unless TYPE_LIST.include?(type)
errors.add(:type, "invalid notification type")
end
end
end