Skip to content

Instantly share code, notes, and snippets.

@andyferra
Created September 25, 2008 23:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyferra/12991 to your computer and use it in GitHub Desktop.
Save andyferra/12991 to your computer and use it in GitHub Desktop.
Generates a per_page select for will_paginate
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
@seyin
Copy link

seyin commented Jan 11, 2012

how can I use it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment