Created
September 26, 2008 04:28
-
-
Save andyferra/13036 to your computer and use it in GitHub Desktop.
Generates per_page links for will_paginate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def per_page_links(collection, options={}) | |
unless collection.empty? | |
separator = options[:seperator] || ' ' | |
css_class = options[:class] || 'per_page_links' | |
param = options[:param] || :per_page | |
per_page = collection.first.class.per_page | |
options = [per_page/2, per_page, per_page*2] | |
value = params[param] || per_page.to_s | |
link = lambda {|p| url_for(params.merge({param => p}))} | |
item = lambda {|p, current_value| current_value == p.to_s ? content_tag(:span, p, :class => 'current') : link_to(p, link.call(p)) } | |
content_tag(:div, options.map {|p| item.call(p, value)}.join(separator), :class => css_class) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment