orbit-basic/vendor/built_in_modules/announcement/app/models/bulletin.rb

55 lines
1.1 KiB
Ruby
Raw Normal View History

2012-01-11 12:31:52 +00:00
# encoding: utf-8
class Bulletin
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes
# field :category_id, :type => Integer
2012-01-12 10:38:50 +00:00
field :title
2012-01-13 11:15:03 +00:00
field :subtitle
2012-01-12 10:38:50 +00:00
field :text
2012-01-11 12:31:52 +00:00
field :postdate , :type => Date
field :deadline , :type => Date
2012-01-12 10:38:50 +00:00
field :url
field :create_user_id
field :update_user_id
2012-01-11 12:31:52 +00:00
2012-01-13 11:15:03 +00:00
field :is_top, :type => Boolean, :default => false
2012-01-11 12:31:52 +00:00
mount_uploader :image, ImageUploader
belongs_to :bulletin_category
# embeds_many :bulletin_files
2012-01-12 10:38:50 +00:00
embeds_many :bulletin_files, :cascade_callbacks => true
# has_many :bulletin_files, :autosave => true, :dependent => :destroy
2012-01-11 12:31:52 +00:00
accepts_nested_attributes_for :bulletin_files, :allow_destroy => true
2012-01-12 10:38:50 +00:00
validates_presence_of :title
2012-01-11 12:31:52 +00:00
after_save :save_bulletin_files
2012-01-13 11:15:03 +00:00
def self.search(search)
find(:all, :conditions => {title: search}).desc( :is_top, :postdate)
end
2012-01-11 12:31:52 +00:00
2012-01-13 11:15:03 +00:00
def is_top?
self.is_top
end
2012-01-11 12:31:52 +00:00
def save_bulletin_files
self.bulletin_files.each do |t|
if t.should_destroy
t.destroy
end
end
end
end