Watched 1 video

Watched 1 Video from start to finish

Subscribed for 1 month

Learning and showing your support for 1 Month

Spread the word 1 time

Referred 1 Member to Drifting Ruby

10

10 times Chatter Box

Make 10 comments to videos or replies to other comments
1/10

10

Share the love 10 times

Liked 10 episodes
6/10

3

Welcome back 3 times

You've visited Drifting Ruby on 3 different days

Suggested 1 episode

Helped the community by suggesting 1 episode

Vote Suggestion 1 time

Helped the community by voting on suggestions 1 time

Share the love 1 time

Liked 1 episode

Earned on 3/4/2019

1 time Chatter Box

Make 1 comment to videos or replies to other comments

Earned on 3/4/2019

mchlfhr said about 2 years ago on Single Table Inheritance :

Hi,

Nice cast! But would it not be possible to dry out the class definitions a little bit more? As Emergency and Friend anyway inherits from Contact, it would also be possible to declare the association and the "similar" validations in there:

class Contact < ApplicationRecord
  scope :friends, -> { where(type: 'Friend') }
  scope :emergencies, -> { where(type: 'Emergency') }
  belongs_to :user 
  validates :last_name, presence: true
  validates :first_name, presence: true
end
class Emergency < Contact
  validates :phone_number, presence: true
end
class Friend < Contact
  validates :birthday, presence: true
end