0
class Material < ActiveRecord::Base
belongs_to :material_type
belongs_to :product_review
validates :url, :presence => true, :if => :url_presence?
validates :video, :presence => true, :if => :video_presence?
def url_presence?
if !self.title.blank? and self.material_type.title.eql? :url
true
end
end
def video_presence?
if !self.title.blank? and self.material_type.title.eql? :video
true
end
end
has_attached_file :video,
:url => "/system/video/:id/:attachment/:style/:basename.:extension",
:path => ":rails_root/public/system/video/:id/:attachment/:style/:basename.:extension",
:default_url => "/image/video.png"
end
I 가정 제목 필드를 입력하고 URL 필드에 존재 유효성 검사에 대한 유효성 검사를 수행보다 material_type은 URL이지만, 그것은 도움이되지레일 액티브 레코드 검증 조건 기반의가 발견되면
질문이 있으십니까? – rwilliams