开发者

Rails, simple pagination

So I have a Photo model of which the first photo that belongs to a certain model shows up in like a modal window, in this case these are photos for recipes. My question is this, how can I know which photo is next in the set of 开发者_C百科all the photos?

def show
  @photo = Photo.find params[:id]
  # @next_photo = ?
  # @previous_photo = ?
end

How can I know which photo of the collection I'm looking at? The photo is actually derived from @recipe.photos in the view for the modal, but how can sort of know which one is next and previous? Or am I going about this all wrong?


Have you tried using something like will_paginate that will do all this for you? You could then just set the per_page to be 1.


something like this?

@recipe_photos = @photo.recipe.photos
@next_photo = @recipe_photos[(@recipe_photos.index @photo) +1]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜