How to customize the will paginate links with images

有些话、适合烂在心里 提交于 2019-12-08 13:46:54

问题


I want to customize the will paginate links in to dotted images instead of numbers 1,2,3. I tried to customize the css of pagination class but it wasn't worked. Pasted below the links format.

(Existing) Previous 1 2 3 Next

(Need to implement) . . . . . . .


回答1:


I know this question is old, but perhaps you still want an answer. This is probably a good starting point. Create a helper such as app/helpers/will_paginate_helper.rb with the following content:

module WillPaginateHelper
  class DottedLinkRenderer < WillPaginate::ActionView::LinkRenderer
    protected
    def link(text, target, attributes = {})
      if target.is_a? Fixnum
        attributes[:rel] = rel_value(target)
        target = url(target)
      end
      attributes[:href] = target
      tag(:a, ".", attributes)
    end
  end

  def dotted_will_paginate(collection, options = {})
    will_paginate(collection, options.merge(:renderer => WillPaginateHelper::DottedLinkRenderer))
  end
end

then in your view use:

<%= dotted_will_paginate @posts %>

This is basically a custom link renderer based on the original link renderer.



来源:https://stackoverflow.com/questions/12507639/how-to-customize-the-will-paginate-links-with-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!