我使用activeadmin注册了相同的模型两次:
ActiveAdmin.register Media, as: 'Picture' do
end
ActiveAdmin.register Media, as: 'Video' do
end
但我希望根据类型有不同的验证。我想为视频设置这个:
models/video.rb
validate :validate_video_count
def validate_video_count
errors.add(:error, "Require minimum 1 video") if self.videos.size < 1
end
And this for the picture :
models/picture.rb
validate :validate_picture_count
def validate_picture_count
errors.add(:error, "Require minimum 1 picture") if self.pictures.size < 1
end
self
是谁:self.pictures.size
和self.videos.size
? - lcguida