I have an album which has_many photos. A counter_cache setup updates the photos_count column in the album table. How do I limit the number of photos for an album?
In my case, it was sufficient to use validates_length_of:
validates_length_of
class Album has_many :photos validates_length_of :photos, maximum: 10 end class Photo belongs_to :album validates_associated :album end
1.4m articles
1.4m replys
5 comments
57.0k users