Search code examples
ruby-on-railsruby-on-rails-3activerecordkaminari

Where does Kaminari calculate it's page url links?


I'm working with a custom model that I made that pretends to be a table based ActiveRecord object. It is instead backed by a SQL view. There's some trickery behind the scenes.

The problem is that pagination links with Kaminari aren't working correctly. They are displaying the correct page numbers and number of page links just to the wrong route.

I need to know where in the Kaminari source it figures out the route to the object it has been set to paginate on. Or if someone is familiar with the active record method name that would be used to calculate that.

I've been searching through the source code and I can't figure it out.

UPDATE
My actual problem was caused by my routes file. I had this entry -

match 'dashboard' => 'users#start', :as => 'user_root'

Instead of my links referring to /users/start?page=x they refereed to /users/dashboard?page=x. I was still at the same controller action but I made view of the page that needed the pagination links from /users/start so I would think that it would use that and not this match rule. Removed the match rule and I'm all set!


Solution

  • The comment above Kaminari::ActionViewExtension#paginate says it accepts :params key in options hash, so you can use it to override the URL parameters:

    paginate @bloops, params: {controller: "foos", action: "index"}
    

    By default it assumes that we're paginating the "current" page, which is the usual case.

    From Kaminari::Helpers::Tag#initialize:

    @params = @options[:params] ? template.params.merge(@options.delete :params) : template.params