-
-
Save gustavowt/599f22715e9f8e27935cb719f31fddde to your computer and use it in GitHub Desktop.
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
class Animal < ApplicationRecord | |
belongs_to :place, polymorphic: true | |
end | |
class Monkey < Animal | |
validates :name, presence: true | |
end | |
class Cat < Animal | |
validates :breed, presence: true | |
end | |
class Jungle < ApplicationRecord | |
has_many :animals, as: :place | |
accepts_nested_attributes_of :animals, | |
end | |
=> jungle = Jungle.new(animals_attributes: [{ type: 'Monkey', name: nil}, { type: 'Cat', beed: nil }]) | |
=> jungle.valid? | |
=> false | |
=> jungle.errors.full_messages | |
=> ["Animals name can't be blank", "Animals breed can't be blank"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment