finally corrected that model thing.

This commit is contained in:
nilsding 2015-01-12 06:41:44 +01:00
parent 5e26d72d91
commit d1a6c512c4
3 changed files with 9 additions and 3 deletions

View File

@ -6,7 +6,13 @@ class Group < ActiveRecord::Base
self.name = self.display_name.downcase.sub(/\s+/, '-')
end
alias members group_members
def add_member(user)
GroupMember.create! group: self, user: user
end
def remove_member(user)
GroupMember.where(group: self, user: user).first!.destroy
end
end

View File

@ -1,4 +1,4 @@
class GroupMember < ActiveRecord::Base
has_one :user
has_one :group
belongs_to :user
belongs_to :group
end

View File

@ -26,7 +26,7 @@ class User < ActiveRecord::Base
has_many :moderation_comments, dependent: :destroy
has_many :moderation_votes, dependent: :destroy
has_many :groups, dependent: :destroy
has_many :group_memberships, class_name: "GroupMember", dependent: :destroy
has_many :group_memberships, class_name: "GroupMember", foreign_key: 'user_id', dependent: :destroy
SCREEN_NAME_REGEX = /\A[a-zA-Z0-9_]{1,16}\z/
WEBSITE_REGEX = /https?:\/\/([A-Za-z.\-]+)\/?(?:.*)/i