问题
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