开发者

Image pagination with Carrierwave and Kaminari

I'm attempting to paginate a series of photos using the Kaminari gem. The images are being displayed in the Dog model's show action, and the photos have been uploaded using CarrierWave to开发者_开发问答 a separate model called DogPhoto. DogPhoto belongs to Dog, and Dog has many DogPhotos.

The Dog controller's show action looks like this (@dog is loaded in a before filter):

def show
  @dog_photos = @dog.dog_photos.page(params[:page]).per(1)
end

And the show view looks like this:

<div id="dog_photos">
  <% if @dog_photos.count > 0 %>
    <% @dog_photos.each do |dog_photo| %>
      <%= image_tag dog_photo.photo_url %>
    <% end %>
    <%= paginate @dog_photos %>
  <% else %>
    <%= image_tag("dog-with-no-photo.png", :border => false) %>
  <% end %>
</div>

When the page is loaded, the pagination links are displayed for the correct number of photos (one page per photo). However, only the first photo is displayed. When the user clicks on "2" it instead shows the dog-with-no-photo.png fallback image.


You should get rid of the .per(1) code in your show action since it limits the number of pictures per page to only one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜