class Shelf < ActiveRecord::Base has_many :comics has_many :books#, validate: -> {self.shelf_of == 'book'} accepts_nested_attributes_for :comics accepts_nested_attributes_for :books # has a dropdown on view for shelf_of that could either be 'comic' or 'book validates :shelf_of, inclusion: { within: %w(comic book) } end class Comic < ActiveRecord::Base end class Book < ActiveRecord::Base validates :title, format: { with: /\Asome_complicated_format\z/i } end