如何自定义带有图像的将分页链接 [英] How to customize the will paginate links with images

查看:39
本文介绍了如何自定义带有图像的将分页链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自定义将分页链接到虚线图像而不是数字 1、2、3.我试图自定义分页类的 css,但没有奏效.粘贴在链接格式下方.

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.

(现有)上一个 1 2 3 下一个

(Existing) Previous 1 2 3 Next

(需要实现).... ...

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

推荐答案

我知道这个问题很老了,但也许您仍然想要答案.这可能是一个很好的起点.使用以下内容创建一个助手,例如 app/helpers/will_paginate_helper.rb:

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 %>

这基本上是一个基于的自定义链接渲染器原始链接渲染器.

这篇关于如何自定义带有图像的将分页链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆