Created
March 20, 2009 19:28
-
-
Save contentfree/82527 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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