問題我有2種型號與驗證
class Variant < ActiveRecord::Base
belongs_to :product
with_options :if => :is_active? do |p_active|
p_active.validates :avatar, :presence => true
end
with_options :if => :isnt_diavoleria? do |p_active|
p_active.validates :color, :presence => true
end
def is_active?
self.product.active
end
def isnt_diavoleria?
a = (self.is_active? and self.product.section_id != 5)
a
end
end
class Product < ActiveRecord::Base
has_many :variants, :autosave => true
accepts_nested_attributes_for :variants
end
如果我更改屬性SECTION_ID或活動的產物,節約,模型變形的驗證與SECTION_ID和積極的舊值執行。 爲什麼?
我該怎麼辦用新值的驗證?
爲了給出一個更可信的答案我們需要在那裏你閱讀的對象以及您對其進行更改(我覺得弗雷德裏克祥是在代碼示例這裏正確的軌道) – LucaM