我有一个相册,里面有很多照片。 counter_cache 设置会更新相册表中的 photos_count 列。如何限制相册的照片数量?
就我而言,使用就足够了validates_length_of
:
class Album
has_many :photos
validates_length_of :photos, maximum: 10
end
class Photo
belongs_to :album
validates_associated :album
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)