company = Company.find(1) company.firm? company.client? company.priority_client?
What about it?
Allen Madsen
unread,
May 20, 2016, 6:07:33 PM5/20/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rubyonra...@googlegroups.com
Typically, when you use STI models it's because the data will be the
same, but the behavior will vary. Because a different class is loaded
based on the STI type, you can handle behavior polymorphically. So
rather than:
if company.firm?
do_thing(company)
end
You would instead do:
company.do_thing
Then each subclass of company would implement the correct behavior for
that case.