Skip to content

Instantly share code, notes, and snippets.

@bradpauly
Created February 20, 2014 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradpauly/9125697 to your computer and use it in GitHub Desktop.
Save bradpauly/9125697 to your computer and use it in GitHub Desktop.
class Pet < ActiveRecord::Base
as_enum :species, {:cat => 0, :dog => 1, :other => 2}, :prefix => true
as_enum :status, {:lost => 0, :found => 1}, :prefix => true
validates :name, :description, :zip, :species_cd, presence: true
validates :zip, numericality: { only_integer: true}
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
scope :lost, -> { where(:status_cd => Pet.status_lost) }
scope :found, -> { where(:status_cd => Pet.status_found) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment