retrospring/app/models/list.rb
Georg Gadinger ea0685136e Rename Groups to Lists
haha regexp go brrr

special thanks to @seatsea for helping me out with the French locales
2020-05-25 18:04:54 +02:00

27 lines
621 B
Ruby

# frozen_string_literal: true
class List < ApplicationRecord
include List::TimelineMethods
belongs_to :user
has_many :list_members, dependent: :destroy
validates :name, length: { minimum: 1 }
validates :display_name, length: { maximum: 30 }
before_validation do
self.display_name.strip!
self.name = self.display_name.parameterize
self.name = '-followers-' if self.name == 'followers'
end
alias members list_members
def add_member(user)
ListMember.create! list: self, user: user
end
def remove_member(user)
ListMember.where(list: self, user: user).first!.destroy
end
end