0
是否有任何理由使用reject_if
并做类似的事情?如果您可以使用验证,为什么会使用reject_if?
class User < ActiveRecord::Base
has_many :posts
accepts_nested_attributes_for :posts, reject_if: proc do |attributes|
attributes['title'].blank?
end
end
而不是在Post模型上使用验证?
class Post < ActiveRecord::Base
belongs_to :user
validates :title, presence: true
end