Last active
November 23, 2019 01:27
-
-
Save harshalbhakta/39a332a5792195a4380bb28b5cefc964 to your computer and use it in GitHub Desktop.
Code Folding Templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
#=region Setup | |
devise :database_authenticatable | |
has_images :icon_image | |
codify( | |
harshal: { name: "Harshal" } | |
) | |
#=endregion | |
#=region Validations | |
validates :name, presence: true | |
validate :age_is_atleast_13 | |
#=endregion | |
#=region Validation Functions | |
def age_is_atleast_13 | |
if age < User.minimum_age | |
errors.add(:age, "cannot be less than 13") | |
end | |
end | |
#=endregion | |
#=region belongs_to | |
belongs_to :country | |
#=endregion | |
#=region has_one | |
has_one :car | |
#=endregion | |
#=region has_many | |
has_many :bills | |
#=endregion | |
#=region scopes | |
scope :married, -> { where(married: true) } | |
#=endregion | |
#=region scopes | |
scope :married, -> { where(married: true) } | |
#=endregion | |
#=region scopes | |
scope :married, -> { where(married: true) } | |
#=endregion | |
#=region before_callbacks | |
before_save :assign_country_if_missing | |
after_save :calculate_tax | |
#=endregion | |
#=region after_callbacks | |
after_create :create_associated_objects | |
after_save :notify_user | |
#=endregion | |
#=region Public Class Methods | |
def self.placeholder_text | |
return "Name - Age" | |
end | |
#=endregion | |
#=region Public Instance Methods | |
def display_name_and_age | |
return "#{name} - #{age}" | |
end | |
#=endregion | |
private | |
#=region Private Class Methods | |
def self.minimum_age | |
return 13 | |
end | |
#=endregion | |
#=region Private Instance Methods | |
def calculate_tax | |
return 100 | |
end | |
#=endregion | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment