Created
April 1, 2019 04:09
-
-
Save ziemekwolski/3cc167d87bee32546542a2882fbc6cb4 to your computer and use it in GitHub Desktop.
Ruby model formatted
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 < ActiveRecord::Base | |
# == Constants ============================================================ | |
GENDERS = [[‘Male’, ‘m’], [‘Female’, ’f’]].freeze | |
# == Attributes =========================================================== | |
# paperclip | |
attr_accessor :remove_logo | |
# == Extensions =========================================================== | |
# globalize required | |
translates :sector, :memo, :fallbacks_for_empty_translations => true | |
# paperclip required | |
has_attached_file :logo, styles: { thumb: ["64x64!", :png] } | |
# == Relationships ======================================================== | |
has_attached_file :avatar, styles: { | |
square_100: ‘100x100#’, | |
square_300: ‘300x300#’ | |
} | |
# association one-to-many | |
has_many :documents | |
# == Validations ========================================================== | |
validates: email, presence: true, uniqueness: true, | |
email_format: true | |
# == Scopes =============================================================== | |
# == Callbacks ============================================================ | |
before_validation :normalize_name, on: :create | |
after_validation :set_location, on: [ :create, :update ] | |
# == Class Methods ======================================================== | |
def self.from_the_class | |
"Hello, from a class method" | |
end | |
def self.for_select | |
all.collect{|u| [“#{u.name} (#{u.email})”, u.id]} | |
end | |
# == Instance Methods ===================================================== | |
def main_method | |
method1 | |
end | |
def from_an_instance | |
"Hello, from an instance method" | |
end | |
protected | |
def method1 | |
puts "Hi this is #{self.class}" | |
end | |
private | |
def normalize_name | |
self.name = name.downcase.titleize | |
end | |
def set_location | |
self.location = LocationService.query(self) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment