Skip to content

Instantly share code, notes, and snippets.

@amiel
Created February 4, 2012 04:40
Show Gist options
  • Save amiel/1735382 to your computer and use it in GitHub Desktop.
Save amiel/1735382 to your computer and use it in GitHub Desktop.
A nice pattern for validating the type in STI
class MyModel < ActiveRecord::Base
include ActiveSupport::DescendantsTracker
validates_inclusion_of :type, :in => direct_descendants.map(&:name)
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment