Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7604331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:53:00+00:00 2026-05-30T23:53:00+00:00

I am using Mongoid with Kaminari for pagination and it is working fine for

  • 0

I am using Mongoid with Kaminari for pagination and it is working fine for models defined within the Rails application itself. However, I am also including a gem which defines several more models, and when I try to use pagination on those models, the ‘page’ method is undefined. It is as though Kaminari doesn’t find those models when initializing.

I’ve tried reordering the initialization process as well as create an initializer that specifically tries to add the scope and Kaminari routines to the Gem models:

GemModel.class_eval do 
  include Kaminari::ConfigurationMethods 

  scope :page, Proc.new {|num|
    limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
  } do 
    include Kaminari::ActiveRecordRelationMethods 
    include Kaminari::PageScopeMethods 
  end
end 

However, this creates an undefined method ‘conditions’ for nil:NilClass from (eval):3:in ‘page’.

Is there any way to get Kaminari to work with models defined in gems?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:53:01+00:00Added an answer on May 30, 2026 at 11:53 pm

    You need to tell Kaminari specifically about the models within a gem if you want to paginate those models. You can do that by adding the following code to your config/environment.rb file or as a separate initializer (e.g. initializers/kaminari.rb).

    GemModel.send(:include, Kaminari::MongoidExtension::Document)
    

    Another thing that tripped me up is that GemModel cannot be a superclass of anything. Otherwise, you will get nil object errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Mongoid, Devise and Rails 3.1. I have four models: Students, Teacher, Parents
I'm writing a ruby on rails application using mongoid and I'm wondering about the
Could somebody give me the working example of nested form using mongoid? My models:
I`m having a problem with search query in Rails 3 application using Mongoid. My
I am currently working on a rails app where we are using mongoid/mongoDB on
I recently played with MongoDB in Rails using Mongoid . I like the ability
I have recently been getting my feet wet in MongoDB using Mongoid w/ Rails
I was writing a Blog like application Using Rails3/Mongoid, and now trying to use
I'm using Rails 3 w/ Mongoid, (so no ActiveRecord). Mongoid uses ActiveModel's to_json method,
I have a Rails 3.1 app, running on Ruby 1.9.2, Mongo 2.0.2, using Mongoid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.