所以我想在一页上使用两次will_paginate插件。我的问题是,当我在其中一个分页(@articles分页)上单击“下一步”时,它还会转到我的其他分页(@comments分页)的下一页。
<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
您:param_name
应该在每个分页语句上指定类似:articles_page
和的内容:comments_page
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句