0
在我的模型文件中,我試圖根據隱藏窗體值進行條件驗證。它看起來像:form_type_main?方法永遠不會被調用,或者只是不起作用。想我做錯了嗎?有條件的驗證RAILS模型
attr_accessor(:form_type,:field1,:field2,:field3,:field4)
required_main = ["field1", "field2"]
required_second = ["field3", "field4"]
if :form_type_main?
required = required_main
else
required = required_second
end
required.each do |i|
validates_presence_of i
end
def form_type_main?
form_type == "main"
end