socialforge/app/models/system_message.rb

21 lines
664 B
Ruby

class SystemMessage < ActiveRecord::Base
attr_accessible :content, :id, :user_id, :description, :subject
belongs_to :user
validates :subject, presence: true
# validates :description, presence: true
validates_length_of :description, maximum: 10000
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
acts_as_attachable
# 系统消息放置总消息列表
after_create :add_system_message
def add_system_message
if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
self.message_alls << MessageAll.new(:user_id => self.user_id)
end
end
end