Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# The models
class User < ActiveRecord::Base
has_many :things
accepts_nested_attributes_for :things
end
class Thing < ActiveRecord::Base
belongs_to :user
validates_presence_of :user_id
validates_presence_of :name # For clarity below
end
# Trying to create a new user with a new thing
u = User.new(:things_attributes => [{:name => 'thing'}])
u.save #=> false
u.errors.full_messages #=> ["Things user can't be blank"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.