Hi Paul
Paul PH wrote:
Hi all, I'd like to write a very simple image gallery, but not sure how to go about navigating the images.
Say I have 10 images, I'd like the image to be on the page with previous and next buttons which load the next image.
I've got a gallery controller, and i can create an array of many image objects, but it's the view that i'm not sure how to do.
are there any tutorials out there that could help? i'm thinking something along the lines of this: http://shopify.com/screenshots/
Have a look at the pagination documentation [1, 2]. You'll probably need something like this in your controller (which gives an image and a Paginator object to the view):
def index @image_pages, @images = paginate :images, :per_page => 1 end
And in your view:
<% @images.each |image| do %> <%= # code to display each image %> <% end %>
<%= link_to "Previous image", { :page => @image_pages.current.previous } if @image_page.current.previous %> <%= link_to "Next image", { :page => @image_pages.current.next } if @image_pages.current.next %>
This is from memory and untested but should give you an idea.
Hope this helps,
Mark
[1] http://api.rubyonrails.org/classes/ActionController/Pagination.html [2] http://api.rubyonrails.org/classes/ActionView/Helpers/PaginationHelper.html