提交 99c092d4 编写于 作者: T Trevor Turk

Note about validates_presence_of and nested attributes

上级 e6b6d3ad
......@@ -202,6 +202,22 @@ class TooManyRecords < ActiveRecordError
# You would need to modify it to look like this:
#
# attr_accessible :name, :posts_attributes
#
# === Validating the presence of a parent model
#
# If you want to validate that a child record is associated with a parent
# record, you can use <tt>validates_presence_of</tt> and
# <tt>inverse_of</tt> as this example illustrates:
#
# class Member < ActiveRecord::Base
# has_many :posts, :inverse_of => :member
# accepts_nested_attributes_for :posts
# end
#
# class Post < ActiveRecord::Base
# belongs_to :member, :inverse_of => :posts
# validates_presence_of :member
# end
module ClassMethods
REJECT_ALL_BLANK_PROC = proc { |attributes| attributes.all? { |_, value| value.blank? } }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册