Created
September 25, 2008 23:55
-
-
Save theconektd/12991 to your computer and use it in GitHub Desktop.
Generates a per_page select for will_paginate
This file contains hidden or 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_select(collection, name=nil, value=nil, options={}) | |
unless collection.empty? | |
per_page = collection.first.class.per_page | |
name = name || 'per_page' | |
value = value || params[:per_page] || per_page.to_s | |
before = options[:before_default] || ["#{per_page/2}"] | |
after = options[:after_default] || ["#{per_page*2}"] | |
choices = options_for_select(before + ["#{per_page}"] + after, value) | |
select_tag name, choices, options | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how can I use it ?