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