내가 몇 가지 유효성 검사와 함께 ActiveRecord 모델을 가지고 있다고 가정 해 봅시다.조건에 레일 4 유효성 검사
class Thing < ActiveRecord::Base
validates_presence_of :title
validates_uniqueness_of :slug
end
이 모델의 개체 생성 또는 업데이트로 유효성 검사를 평가할지 여부를 조건으로 지정하는 방법을 찾고 있습니다.
이 작품이 마음에 드시나요?
#pseudocode
class Thing < ActiveRecord::Base
if conditions
validates_presence_of :title
validates_uniqueness_of :slug
end
end
모범 사례가 있습니까? 아니면이 모든 접근법을 가짜라고 생각합니까?
전자 메일 예보기 http://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validates – devanand