Are you sure this is working code?
@gallery_images = @tournaments.gallery_images.paginate(:page => params[:page], :per_page => 9)
You are calling gallery_images
, what appears to be an instance method, on an ActiveRecord collection, which is essentially an array. That won't work.
I suspect you want to loop over the tournaments and call paginate on the images of each tournament.
<% @tournaments.each do |t| %>
<%= will_paginate t.gallery_images.paginate(page: params[:page], per_page: 9) %>
<% end %>
You can create an instance method on the Tournament
model to save you from writing all that each time you want to paginate tournament images.
class Tournament
def paginated_images(page, per_page = 9)
gallery_images.paginate(page: page, per_page: per_page)
end
end
Then you can do this in your view:
<% @tournaments.each do |t| %>
<% images = t.paginated_images(params[:page]) %>
<% images.each do |image| %>
<%= image_tag image %>
<% end %>
<%= will_paginate images %>
<% end %>