【问题标题】:How to add an anchor at the end of paginate url in will_paginate [duplicate]如何在 will_paginate 中的分页 URL 末尾添加一个锚点 [重复]
【发布时间】:2014-02-06 07:22:23
【问题描述】:

您好,我在使用 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

【问题讨论】:

  • @volunteers 是一个集合

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


【解决方案1】:
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”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 2020-04-23
    • 1970-01-01
    • 1970-01-01
    • 2014-09-23
    • 2017-06-15
    相关资源
    最近更新 更多