nccu-news/app/models/unit.rb

24 lines
480 B
Ruby

# encoding: utf-8
class Unit
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :name, as: :slug_title, :localize => true
field :sort_number, type: Integer
has_many :departments, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :departments, :allow_destroy => true
after_save :save_departments
def save_departments
self.departments.each do |t|
if t.should_destroy
t.destroy
end
end
end
end