Skip to content

Instantly share code, notes, and snippets.

@gbenedict
Last active February 3, 2016 15:49
Show Gist options
  • Save gbenedict/0715b6e58d72560a1800 to your computer and use it in GitHub Desktop.
Save gbenedict/0715b6e58d72560a1800 to your computer and use it in GitHub Desktop.
ActiveRecord Model Style Guide
class Company
# includes
extend FriendlyId
friendly_id :name, use: :slugged
devise :database_authenticatable, :token_authenticatable, :recoverable, :trackable, :invitable, :timeoutable
# constants
TYPES = %w(small medium giantess)
# attr_* and cattr_* macros
attr_accessor :date_of_incorporation
attr_accessible :name, :address, :city, :state, :zip
# aliases
alias :story :commentable
alias :idea :commentable
# associations
has_many :people
belongs_to :country
has_attached_file :file, PAPERCLIP_OPTIONS
# validations
validates :name, presence: true
# callbacks
before_save :update_coordinates
# other macros
accepts_nested_attributes_for :people
# scopes
default_scope { where(active: true) }
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
# class methods
def self.types
TYPES
end
# public methods
def full_address
end
# protected methods
protected
def floor
end
private
def floor2
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment