Rails3: How to pass param into custom will_paginate renderer?

后端 未结 2 1430
心在旅途
心在旅途 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:46

    will_paginate lets you pass in :params for the links:

    will_paginate(@user_friends, :params => { :user_id => 95 })
    
    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题