clarion/app/models/volunteer_team.rb

24 lines
631 B
Ruby
Raw Permalink Normal View History

2015-09-01 11:09:26 +03:00
class VolunteerTeam < ActiveRecord::Base
belongs_to :conference
has_many :volunteers, inverse_of: :volunteer_team
has_and_belongs_to_many :supporters, class_name: "Volunteer", inverse_of: :additional_volunteer_teams
2015-09-01 11:09:26 +03:00
validates :name, presence: true
validates :color, presence: true, format: {with: /\A#?[a-f0-9]{6}\z/i}
validates :description, presence: true
translates :name, :description
def include?(volunteer)
volunteers.include? volunteer
end
2015-09-01 11:09:26 +03:00
def color=(hex_triplet)
2019-04-28 21:10:54 +03:00
write_attribute :color, hex_triplet.gsub(/\A#/, "") if hex_triplet
2015-09-01 11:09:26 +03:00
end
def color
"##{read_attribute :color}"
end
end