Skip to content

Instantly share code, notes, and snippets.

@mclosson
Last active December 17, 2015 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mclosson/5518414 to your computer and use it in GitHub Desktop.
Save mclosson/5518414 to your computer and use it in GitHub Desktop.
Example double error output for https://github.com/rails/rails/issues/10336
class Guaranty < ActiveRecord::Base
belongs_to :product
accepts_nested_attributes_for :product
validates :name, presence: true
end
class Product < ActiveRecord::Base
has_many :guaranties
accepts_nested_attributes_for :guaranties
validates :name, presence: true
end
$ rails new issue10336
$ cd issue10336
$ rails g model guaranty name:string product_id:integer
$ rails g model product name:string
$ rake db:migrate
$ rails console
Loading development environment (Rails 4.0.0.rc1)
1.9.3-p194 :001 > g = Guaranty.new
=> #<Guaranty id: nil, name: nil, product_id: nil, created_at: nil, updated_at: nil>
1.9.3-p194 :002 > p = Product.new
=> #<Product id: nil, name: nil, created_at: nil, updated_at: nil>
1.9.3-p194 :003 > p.guaranties << g
=> #<ActiveRecord::Associations::CollectionProxy [#<Guaranty id: nil, name: nil,
product_id: nil, created_at: nil, updated_at: nil>]>
1.9.3-p194 :006 > g.product = p
=> #<Product id: nil, name: nil, created_at: nil, updated_at: nil>
1.9.3-p194 :007 > p.valid?
=> false
1.9.3-p194 :008 > p.errors.full_messages
=> ["Name can't be blank", "Name can't be blank",
"Guaranties product name can't be blank", "Guaranties name can't be blank"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment