繁体   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