37 lines
817 B
Ruby
37 lines
817 B
Ruby
|
# encoding: utf-8
|
||
|
|
||
|
class Bulletin
|
||
|
include Mongoid::Document
|
||
|
include Mongoid::Timestamps
|
||
|
include Mongoid::MultiParameterAttributes
|
||
|
|
||
|
# field :category_id, :type => Integer
|
||
|
field :title, :type => String
|
||
|
field :subtitle, :type => String
|
||
|
field :text, :type => String
|
||
|
field :postdate , :type => Date
|
||
|
field :deadline , :type => Date
|
||
|
|
||
|
mount_uploader :image, ImageUploader
|
||
|
|
||
|
belongs_to :bulletin_category
|
||
|
|
||
|
# embeds_many :bulletin_files
|
||
|
has_many :bulletin_files, :autosave => true, :dependent => :destroy
|
||
|
|
||
|
accepts_nested_attributes_for :bulletin_files, :allow_destroy => true
|
||
|
|
||
|
validates_presence_of :title, :subtitle, :text
|
||
|
|
||
|
after_save :save_bulletin_files
|
||
|
|
||
|
|
||
|
def save_bulletin_files
|
||
|
self.bulletin_files.each do |t|
|
||
|
if t.should_destroy
|
||
|
t.destroy
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|