I have a model that has the following association:
class Tournament < ActiveRecord::Base
has_one :gallery, dependent: :destroy
has_many :gallery_images, :through => :gallery, dependent: :destroy
end
I would like to paginate just the gallery_images as opposed to the tournament itself but as I am getting the gallery_images as a nested attribute I'm not sure how to do this using will_paginate
Controller
def galleries
@tournaments = Tournament.all
#tried this
@gallery_images = @tournaments.gallery_images.paginate(:page => params[:page], :per_page => 9)
end
View
<% @tournaments.each do |t| %>
<div>
<div class="clear"></div>
<ul class="team-gallery">
<% t.gallery_images.each do |g| %>
<li>
<%= link_to image_tag(g.photo.url(:gallery_large)), g.photo.url(:gallery_large), class: 'clb-photo' %>
</li>
<% end %>
</ul>
</div>
How can I paginate just the t.gallery_images?