I have the following two models:
photoalbums
has_many:photos
photos
belongs_to:photoalbums
When I show a list of all the photoalbums, I want to also say how many photos exist in the album:
Controller:
def index
@photoalbums = PhotoAlbum.all
end
View:
<%# Get the number of photos per this album %>
<% @photos = Photo.find_by_photo_album_id(photoalbum.id) %>
<li><%= @photos.count %> Photos</li>
The above isn't allowing me to do @photos.count
or @photos.record
in the view.
Is there a better way to do this in the controller? I thought about perhaps an include(:photos)
in the controller?
Thanks!!!