Reputation: 63
I have a nav-tab (twitter-bootstrap) in my homepage with 2 tabs. Under each tab I render a different collection:
home_controller.rb:
def index
@deleted_posts = Post.all.where(status: "deleted").paginate(page: params[:page], per_page: 5)
@edited_posts = Post.all.where(status: "edited").paginate(page: params[:pr_page], per_page: 5)
end
index.html.erb:
<div class="tabbable">
<ul class="nav nav-pills">
<li class="active"><a href=<%="#tabDeleted"%> data-toggle="tab"><%= t "deleted" %></a></li>
<li><a href=<%= "#tabEdited" %> data-toggle="tab"><%= "edited" %></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id=<%="tabDeleted" %>>
<%= render @deleted_posts %>
<%= will_paginate @deleted_posts, renderer: BootstrapPagination::Rails %>
</div>
<div class="tab-pane" id=<%="tabEdited" %>>
<%= render @edited_posts %>
<%= will_paginate @edited_posts, renderer: BootstrapPagination::Rails, :param_name => "pr_page" %>
</div>
</div>
</div>
The pagination works fine within the first tab (deleted_posts).
When I switch to the second tab (edited_posts) the first page is shown correctly, although my url still shows the page params of the first tab:
http://localhost:3000/home/index?page=3
and when I try to go to another page it directs me to the first page of the first tab (deleted_posts) and the page param is just being added to the url:
http://localhost:3000/home/index?page=3&pr_page=2
How do I fix it? And maybe this is actually the question: Since Twitter Bootstrap nav-tabs don't add params to the url, how can my app know in which tab the user is? And how to I delete the page params from the wrong tab to the url (because as is, it adds both tabs' page params to the url)?
Upvotes: 2
Views: 541
Reputation: 13077
Specify :param_name
on both calls to will_paginate
function. Specifying :param_name
on only one call is making it add the default :page
param to both paginations.
Eg:
<%= will_paginate @deleted_posts, renderer: BootstrapPagination::Rails, :param_name => "deleted_posts" %>
<%= will_paginate @edited_posts, renderer: BootstrapPagination::Rails, :param_name => "edited_posts" %>
Upvotes: 2