will_paginate is there a way to set per_page to 'all'
Rails 2.3.5 / Will_Paginate Gem 2.3.15
I have a page section where a user can select how many items per page to display (with an 'all' choice). I don't like having 'all' in there but each item in the list has a checkbox so that bulk operations can be performed against the listed items (a user couldn't select all items the query would return if the items are broken out into pages).
I haven't found an answer looking around, but is there a way to set the :per_page option to 'all'? I temporarily just put in a jumbo number (1000000) as a work-around. Is that the only way to do it?
I thought about just replacing the paginate_by_sql condition with a find_by_sql, but then in the view I'd have to add in logic to not write the "<%= will_paginate @items%>"
if cookies[:items_per_page]
if cookies[:items_per_page] == 'ALL'
@items = Item.paginate_by_sql(sql, :page => params[:page], :per_page => 1000000)
elsif %w(10 20 30 40 50 75 100).any? {|str| cookies[:items_per_page].include? str}
@items = Item.paginate_by_sql(sql, :page => params[:page开发者_如何学Go], :per_page => cookies[:items_per_page].to_i)
else #cookie doesn't contain a valid choice, default to '10'
@items = Item.paginate_by_sql(sql, :page => params[:page], :per_page => 10)
end
else #cookie doesn't exist, default to '10'
@items = Item.paginate_by_sql(sql, :page => params[:page], :per_page => 10)
end
Item.paginate_by_sql(sql, :page => params[:page], :per_page => Item.count)
精彩评论