will_paginate with twitter bootstrap选项卡会在下一页上加载默认的活动选项卡

时间:2015-12-23 00:16:24

标签: ruby-on-rails twitter-bootstrap will-paginate

所以我正在运行rails 4并且有一个使用twitter bootstrap tabs/nav的页面,每个标签上也有will_paginate

我遇到的问题是当我更改页码时,它会返回默认的活动选项卡而不是我正在分页的选项卡。

代码如下:

控制器

....
def admin
   @quotes = Quote.paginate(page: params[:quotes_page], :per_page => 20).order("created_at DESC")
   @users = User.paginate(page: params[:users_page], :per_page => 20).order("created_at DESC") 
   @blogs = Blog.paginate(page: params[:blogs_page], :per_page => 20).order("created_at DESC")
end
....

view.html.erb

<div class="tabbable tabs-left">
<div class="row">
  <div class="col-md-4">
    <ul class="nav nav-pills nav-stacked">
      <li class="active"><a href="#users-tab" data-toggle="tab">Users</a></li>
      <li class=""><a href="#quote-tab" data-toggle="tab">Quotes</a></li>
      <li class=""><a href="#blog-tab" data-toggle="tab">Blogs</a></li>
    </ul>
  </div>
  <div class="col-md-8">
    <div class="tab-content">

      <div class="tab-pane fade in active" id="users-tab">
        <div class="tabbable tabs-left">
          <ul class="nav nav-tabs">
            <li class=""><a href="#user-index" data-toggle="tab">List Users</a></li>
          </ul>
          <div class="tab-content">
            <div class="tab-pane in active" id="user-index">
              <%= render :template => 'users/index' %>
            </div>
          </div>
        </div>
      </div>
      <div class="tab-pane fade in" id="quote-tab">
        <div class="tabbable tabs-left">
          <ul class="nav nav-tabs">
            <li class="active"><a href="#quote-new" data-toggle="tab">New Quote</a></li>
            <li class=""><a href="#quote-index" data-toggle="tab">List Quote</a></li>
          </ul>
          <div class="tab-content">
            <div class="tab-pane in active" id="quote-new">
              <%= render "quotes/fields", :quote => Quote.new %>
            </div>
            <div class="tab-pane in" id="quote-index">
              <%= render :template => 'quotes/index' %>
            </div>
          </div>
        </div>
      </div>
     .... More code of the same
     </div>
  </div>
</div>

用户/ index.html.erb

<div>
  <%= will_paginate @users, :param_name => 'users_page'  %>
  <% @users.each do |u| %>
  .....
  <% end %>
</div>

报价/ index.html.erb

<div>
  <%= will_paginate @quotes, :param_name => 'quotes_page'  %>
  <% @quotes.each do |u| %>
  .....
  <% end %>
</div>

所以我想要了解的是如何使它成为如果我在引号选项卡中并单击第二页的分页链接,它保留在引号选项卡中而不是将页面重新加载回默认的活动选项卡用户。

我注意到的其他内容,如果我点击所有不同的分页链接,它只会添加到参数中。

即。如果我去引用第2页和用户第4页,则网址如下所示:

http://something.com/view?quotes_page=2&users_page=4

我希望它只保留一个参数,例如:

http://something.com/view?users_page=4

1 个答案:

答案 0 :(得分:3)

您可以添加

<%= will_paginate @quotes, :param_name => 'quotes_page', params: {active_tab: 'quotes'}  %>

并且

<div class="tab-pane fade in #{'active' if params[:active_tab] == 'quotes'}" id="quote-tab">

与用户标签相同。有关详细信息,请参阅:https://github.com/mislav/will_paginate/wiki/API-documentation