验证嵌套属性

时间:2011-12-14 05:57:18

标签: ruby-on-rails-3

为什么ResourceAllocation中的验证没有被调用?

class Employee < ActiveRecord::Base 
         has_many :resource_allocations
         accepts_nested_attributes_for :resource_allocations
         validates_associated :resource_allocations
    end


class ResourceAllocation < ActiveRecord::Base
  belongs_to :employee

  validate :location_id, :presence => true
  validate :department_id, :presence => true
  validate :period_from, :presence => true
  validate :period_to, :presence => true
  validate :allocation, :presence => true, :numericality => true
end

0 个答案:

没有答案