簡體   English   中英

Rails redirect_to錨點和will_paginate gem問題

[英]Rails redirect_to anchor and will_paginate gem issue

我有一個帖子控制器,當我更新自己的帖子時,我會通過一個定位標記重定向到特定的帖子。 我在帖子中使用will_paginate gem。 我每四個帖子分頁一次,所以發生的是重定向到anchor tag的操作對列出的前四個帖子有效,但是由於分頁,即使顯示了正確的URL,它也不適用於四個之后的任何其他帖子。 這意味着它不會將redirect_to重定向到四個之后的任何帖子。 例如,如果我將will_paginate更改為每10個分頁,則它將正確列出第11個URL(如果我更新的是URL),但是由於未加載超過10個的帖子,因此不會顯示html / anchor。

網址

http://localhost:3000/groups/16#5 CORRECT URL BUT DOESN'T LOAD THE ADDITIONAL COMMENTS AND DISPLAY

帖子控制器

def update
  @group = Group.find(params[:group_id])
  if @post.update(post_params)
    redirect_to group_path(@group, anchor: "#{@post.id}")
  else
    render :edit
  end
end

發布_post.html.erb

...
<p class="postParagraph" id="<%= post.id %>"><%= post.caption %> </p>

will_paginate

@posts = @group.posts.paginate(page: params[:page], per_page: 4).order('created_at DESC')

您是否在Post模型中添加了post.rb self.per_page

例如self.per_page = 10

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM