Rails3: How to pass param into custom will_paginate renderer?

后端 未结 2 1432
心在旅途
心在旅途 2021-02-13 18:17

I\'ve got a custom will_paginate renderer that overrides WillPaginate::ViewHelpers::LinkRenderer\'s link method like so:

   def link(text, target, attributes = {         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-02-13 18:55

    View:

    <%= will_paginate @user_friends, :renderer => 'FriendsRenderer',
                             :remote => true,
                             :link_path => friends_widget_user_path(@user) %>
    
    class FriendsRenderer < WillPaginate::LinkRenderer
      def prepare(collection, options, template)
        @link_path = options.delete(:link_path)
        super
      end
    
    protected
      def link(page, text, attributes = {})
        # Here you can use @link_path   
      end
    end
    

    Note that this works for the will-paginate version: 2.3.6

提交回复
热议问题