Controller:
class GalleriesController < ApplicationController
def index
@galleries = Gallery.all
end
end
View:
<% for gallery in @galleries %>
<%= image_tag(gallery.image.url(:medium)) %>
<% end %>
I have 2 models, Photo which belongs to Gallery,which has many Photos.
I want to display an image (preferably random rather than :first) from each gallery on the gallery index page.
I know the code I have is wrong as I haven't described which image to select from the gallery, but I'm not sure how to do this... I thought that using @photos = @galleries.photos.find(:first)
would work but I get an undefined method 'photos' in the controller.