Ruby on rails 正在验证属于关联的项目

Ruby on rails 正在验证属于关联的项目,ruby-on-rails,validation,model,Ruby On Rails,Validation,Model,我试图验证一个像这样的模范学生 class Student < ActiveRecord::Base belongs_to :room end 但这并没有改变人们的行为。。 API说: :validate If false, don’t validate the associated objects when saving the parent object. false by default. 因此,我将验证更改为room: class Room < ActiveRec

我试图验证一个像这样的模范学生

class Student < ActiveRecord::Base
  belongs_to :room
end
但这并没有改变人们的行为。。 API说:

:validate
  If false, don’t validate the associated objects when saving the parent object. false by default.
因此,我将验证更改为room:

class Room < ActiveRecord::Base
  has_many :students, :validate => true
end
教室true
结束
但这两种选择都不能解决我的问题

有什么想法吗?

试试看

class Student < ActiveRecord::Base
  belongs_to :room
  validates_associated :room
end
class-Student
我正在查看API文档的这一部分:

另外,注意不要在关联的双方都使用该验证

class Student < ActiveRecord::Base
  belongs_to :room
  validates_associated :room
end