-
-
Save regedarek/1770515 to your computer and use it in GitHub Desktop.
sti
This file contains 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
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