orbit4-5/app/models/group.rb

28 lines
764 B
Ruby

class Group
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :title, as: :slug_title, type: String, localize: true
field :description, localize: true
field :admins, type: Array, default: []
field :privacy, default: "closed"
field :permission, default: "write"
field :archive, type: Boolean, default: false
mount_uploader :image, ImageUploader
belongs_to :group_category
has_and_belongs_to_many :users
has_many :group_posts, :dependent => :destroy
scope :closed, ->{ where(privacy: "closed") }
scope :open, ->{ where(privacy: "open") }
scope :archived, ->{ where(archive: true) }
scope :not_archived, ->{ where(archive: false) }
def privacy_name
return self.privacy == "closed" ? "private" : "public"
end
end