Will_Paginate is it possible to let the user select the # of paginated records?
I have a paginated list, and a select box of numbers showing how many pages 开发者_StackOverflow中文版to display. When the user picks a value I want the screen to refresh with the resized list.
View:
<%= select_tag :paginate_size, options_for_select([['Display: 5', 5],['Display: 10',10],['Display: 20', 20],['Display: 30', 30],['Display: 50', 50],['Display: 100',100]]), :onchange => remote_function(:url => {:action => :show_my_entries}, :with =>"'paginate_size='+value")%>
When I select a value I can see in the log that the show_my_entries function is being called and sent the paginate_size parameter.
In the controller I set the per_page variable as shown below, however selecting anything in the list doesn't refresh the screen with the new list size:
def show_my_entries
if (params[:paginate_size].nil?)
paginate_size = 8
else
paginate_size = params[:paginate_size]
end
@entries = Entry.find_all_my_entries_by_pub(session[:publication_id], session[:user_id])
@entries_paginate = Entry.paginate :page => params[:page], :order => 'title', :per_page => paginate_size, :conditions => "publication_id = " + session[:publication_id].to_s + " AND writer_id = " + session[:user_id].to_s
render :layout => "dashboard"
end
You're missing the :update
parameter in the remote_function
which should point to the id of the HTML element containing the entries list.
So, if the content is, for example, done like this:
<div id="my_entries">
<%= print_entries_list %>
</div>
Your remote function should be like this:
remote_function(:update => "my_entries", :url => {:action => :show_my_entries}, :with =>"'paginate_size='+value")
精彩评论