Skip to content

Instantly share code, notes, and snippets.

@regedarek
Created February 8, 2012 15:38
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 regedarek/1770515 to your computer and use it in GitHub Desktop.
Save regedarek/1770515 to your computer and use it in GitHub Desktop.
sti
Ride coordination board: Singe Table Inheritance
Database: ads
:title
:price
:content
:username
:from
:to
Model: regular AD
:title
:price
:content
:username
Model: Ride AD
:title
:price
:content
:username
---
:from
:to
###############################################
class Ad < ActiveRecord::Base
validates_presence_of :name, :email, :price, :category_id
validates_presence_of :title, :ad_content, if: is_regular?
validates_presence_of :from, :to, unless: is_regular?
def is_regular?
self.type.nil?
end
end
class RideAd < Ad
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment