如何在will_paginate中的paginate url末尾添加一个锚点

时间:2014-02-06 07:22:23

标签: ruby-on-rails ruby pagination will-paginate

你好我在使用will paginate gem时遇到了问题。我想在我的主播标签下打开所有分页,这是"志愿者"。

分页生成的链接类似于"/project_name?page=2"但我想在链接中也包含我的锚标签。就像链接应该是"/project_name?page=2#volunteers"一样。每次用户点击下一页时,如何获得此链接?

在projects_controller.rb

def show
    @volunteers=@volunteers.paginate(:page => params[:page], :per_page => 3 )
    end

在show.html.slim

=will_paginate @volunteers

1 个答案:

答案 0 :(得分:2)

I got the solution finally that can add an anchor to the links so that the page redirects to the desired tab.In view replace
will_paginate @volunteers
with 
will_paginate @volunteers,:container => false,:params => {:anchor => "volunteers"}

这将生成一个新的网址,例如'/ projects?page = 2#volunteers'。