2015-01-08 04:16:13 -08:00
|
|
|
class Group < ActiveRecord::Base
|
|
|
|
belongs_to :user
|
2015-01-10 14:29:04 -08:00
|
|
|
has_many :group_members, dependent: :destroy
|
|
|
|
|
|
|
|
before_validation do
|
|
|
|
self.name = self.display_name.downcase.sub(/\s+/, '-')
|
|
|
|
end
|
|
|
|
|
2015-01-11 21:41:44 -08:00
|
|
|
alias members group_members
|
|
|
|
|
2015-01-10 14:29:04 -08:00
|
|
|
def add_member(user)
|
|
|
|
GroupMember.create! group: self, user: user
|
|
|
|
end
|
2015-01-11 21:41:44 -08:00
|
|
|
|
|
|
|
def remove_member(user)
|
|
|
|
GroupMember.where(group: self, user: user).first!.destroy
|
|
|
|
end
|
2015-01-08 04:16:13 -08:00
|
|
|
end
|