Element slider in Ruby on Rails
I开发者_如何学编程'm working on a Rails3 application. I'm trying to create a slider type display where 5 elements (from a table in the database) are on the page in a row and on both sides there are arrows.
What i want is that by pressing the arrows, the next (or prev, depending on the arrow) element will be displayed by re-rendering the whole slider and replacing the content with the appropriate elements. At all times i want 5 elements to be displayed on the page and each click of an arrow will seem to make one element disappear on one side and another to appear on the other side. I also want it to be a round slider, meaning It never ends just jumps from the last element to the first.
How do i achieve this. All the work should be done within the controller. In addition I want the starting point of the elements to be randomized, meaning that on the first load of the page the slider may be in the middle of it's cycle. Any ideas?
I'd rather better ways than re-rendering the whole slider, like simply changing its content by AJAX and only changing what must be changed.
What you are looking for is a carousel. There are many plugins to do this if you are using any of the JavaScript libraries like JQuery or PrototypeJS. This is an example of one such thing. And here is a list of Top 10 Javascript slideshows, carousels and sliders.
These two videos might help
- http://railscasts.com/episodes/254-pagination-with-kaminari
- http://railscasts.com/episodes/51-will-paginate
If you used will_paginate for example you could set your controller as follows
def self.search(search, page)
paginate :per_page => 5, :page => page,
:conditions => ['name like ?', "%#{search}%"],
:order => 'name'
end
Then just use CSS to skin the navigation as you need it information on that here
- Pagination 101
- Pagination Gallery
精彩评论