1
所以我想在一個頁面上使用兩次will_paginate插件。我的問題是,當我點擊其中一個分頁(@articles分頁)時,它也會轉到另一個分頁(@comments分頁)的下一頁。Ruby on Rails - 在一個視圖中對兩個列表進行分頁的正確方法
<div class="row">
<div class="span6">
<h3>Posted Articles (<%= @articles.count %>)</h3>
<ol class="user_articles">
<% @articles.each do |article| %>
<li>
<span class="content"><%= link_to article.title, article.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(article.created_at) %> ago to <%= article.article_type %>.
</span>
<div>
<% if current_user?(article.user) %>
<%= link_to "delete", article, method: :delete,
data: { confirm: "You sure?" },
title: article.title %>
<% end %>
</div>
</li>
<% end %>
</ol>
<%= will_paginate @articles %>
</div>
<div class="span6">
<h3>Comments (<%= @comments.count %>)</h3>
<ol class="user_comments">
<% @comments.each do |comment| %>
<li>
<span class="content"><%= comment.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(comment.created_at) %> ago to <%= link_to Article.find_by_id(comment.article_id).title, Article.find_by_id(comment.article_id) %>.
</span>
<div>
<% if current_user?(comment.user) %>
<%= link_to "delete", comment, method: :delete,
data: { confirm: "You sure?" },
title: comment.content %>
<% end %>
</div>
</li>
<% end %>
</ol>
<%= will_paginate @comments %>
</div>
</div>
我知道你可以指定一個:PARAM_NAME選項來告訴will_paginate要用於頁碼的參數的名字,但我不知道是什麼:PARAM_NAME我應該爲了使用它的工作。任何幫助將不勝感激!
編輯:
下面是我的看法用戶控制器:
def show
@user = User.find(params[:id])
@comments = @user.comments.paginate(page: params[:page], :per_page => 20)
@articles = @user.articles.paginate(page: params[:page], :per_page => 20)
end
您還必須考慮分頁鏈接到的任何控制器中的不同名稱。 – Eric 2015-02-23 20:30:26
我已經試過,但它永遠不會去我的評論或文章列表的第二頁。 – alcol92 2015-02-23 20:33:33
請編輯您的問題以添加相關的控制器代碼 – Eric 2015-02-23 20:35:12