class ApplyAddSchools < ActiveRecord::Base # status:0 未审批 ; 1 已批阅 attr_accessible :address, :city, :name, :province, :remarks, :school_id, :status has_many :applied_messages, :class_name =>'AppliedMessage', :as => :applied, :dependent => :destroy belongs_to :school after_create :send_massage #给系统所有管理发送消息 def send_massage users = User.where(:admin => 1) users.each do |user| self.applied_messages << AppliedMessage.new(:user_id => user.id, :viewed => false, :status => false) end end end