Pretty much a follow up to my previous thread on here but thought it warranted it's own topic.
I have 3 models:
has_many collections as children
belongs_to collection as parent
Basically I want to write an instance method for a collection to return the total number of photos of ALL children albums including all those albums in children collections of the calling collection.
So for example:
Calling photo_count on collection 1 would return 21 and calling it on collection 2 would return 11Code:
Album 1 - 5 photos
Album 2 - 6 photos
Album 3 - 10 photos
I have tried to write it as follows but it's not quite right, I realise I need to use a try method somewhere but i'm just not sure how to finish it off.
def photo_count count = 0 albums.each do |album| count += album.photo_count end end
Could anyone give me a hand here?