Skip to content

Instantly share code, notes, and snippets.

@alecguintu
Last active August 29, 2015 14:10
Show Gist options
  • Save alecguintu/c9cb5c29398e08575250 to your computer and use it in GitHub Desktop.
Save alecguintu/c9cb5c29398e08575250 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment