Search code examples
ruby-on-railskaminariapotomo

Kaminari in Apotomo widget, links messed up


I have Kaminari pagination inside an apotomo widget. The pagination links render as expected until an apotomo event is fired. Then the pagination links render with a href that appears to be the url of the previous apotomo event:

transactions/render_event_response?...various parameters....

This is driving me nuts. Is there some confusion with a url_for_event method between apotomo and kaminari or something?

Rails 3.2.3 Apotomo 1.2.3 Kaminari 0.14.1


Solution

  • This is an issue with Kaminari, I've added a fix in my code that strips the unwanted data from the url that is added by Kaminari in views rendered from an apotomo event.

    In application_helper.rb:

      def strip_apotomo_data_from_kaminari_url(url)
        url.gsub!('/render_event_response', '')
        if url =~ /\?/
          param_list = url.split('?')[1].split('&')
          param_list.reject!{ |p| p.start_with?('source', 'type') }
    
          url = url.split('?')[0] # strips all params
          url += '?'+ param_list.join('&')
        end
        url
      end
    

    Then I called this helper to update the url from the 5 Kaminari pagination link partials: _page.html.erb, _first_page.html.erb and _last_page.html.erb, _prev_page.html.erb and _next_page.html.erb. (see the answer to Unwanted form parameters being appended to pagination links).

    Thanks to apotomo's Nick Sutterer for pointing me in the right direction https://groups.google.com/forum/?fromgroups=#!topic/cells-and-apotomo/vekawcXAHN0

    The Kaminari bug is: https://github.com/amatsuda/kaminari/issues/131