There is a parameter called "renderer" that you can pass to specify which renderer class to use for will_paginate function. The default is LinkRenderer. In my solution you have to write a new class which will be child of LinkRenderer class. And you will pass this class as a parameter to will_paginate function. Simple.
Here how you define drive the class. The name of file is fb_link_renderer.rb and I placed it under lib folder.
class FBLinkRenderer < WillPaginate::ViewHelpers::LinkRenderer
and than you rewrite in link function. The link function is a private function as it is in LinkRenderer class.
def link(text, target, attributes = {})
if target.is_a? Fixnum
attributes[:rel] = rel_value(target)
target = url(target)
end
attributes[:href] = target
attributes[:target] = "_top"
tag(:a, text, attributes)
end
Here is the complete code for the new class
class FBLinkRenderer < WillPaginate::ViewHelpers::LinkRenderer private def link(text, target, attributes = {}) if target.is_a? Fixnum attributes[:rel] = rel_value(target) target = url(target) end attributes[:href] = target attributes[:target] = "_top" tag(:a, text, attributes) end end
and here is how you use it
= will_paginate(data, :params => "apps.facebook.com/fb-app-name", :renderer => 'FBLinkRenderer')
No comments:
Post a Comment