Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `paginate' with rails 6 #53

Closed
zaoldreck opened this issue Aug 7, 2020 · 12 comments
Closed

undefined method `paginate' with rails 6 #53

zaoldreck opened this issue Aug 7, 2020 · 12 comments

Comments

@zaoldreck
Copy link

ruby 2.6.6
rails 6.0.2.2

error undefined method `paginate'

Noted:

  • include Grape::Kaminari in api
  • try with rails loader classic but still error
@dim
Copy link
Member

dim commented Aug 7, 2020

I unfortunately cannot recreate your issue. Did you include a paginate block/line in the endpoint description? I would need to see some code or a small demo app.

@zaoldreck
Copy link
Author

class CustomersAPI < Grape::API
  include Grape::Kaminari

  resource :customers do
    desc 'GET /api/v1/customers'
    paginate per_page: 20, max_per_page: 30, offset: 1
    params do
      optional :query, type: String
    end
    get do
      users = User.search_by_email(params[:query])
      render_json(:ok, CustomerSerializer.new(users))
    end
  end
end

@dim
Copy link
Member

dim commented Aug 10, 2020

Closing in favour of #54

@dim dim closed this as completed Aug 10, 2020
@bsodmike
Copy link

bsodmike commented Aug 14, 2020

This is breaking in Ruby ruby 2.5.1p57 with latest version grape-kaminari 0.3.0. I'm seeing the same issue with grape-kaminari v0.2.1 as well.

@bsodmike
Copy link

bsodmike commented Aug 14, 2020

Adding config/initializers/grape-kaminari.rb got it working with gem 'grape-kaminari', '~> 0.2.1':

Grape::API::Instance.include(Grape::Kaminari)

@dim
Copy link
Member

dim commented Aug 14, 2020

@bsodmike CI looks OK - https://travis-ci.org/github/bsm/grape-kaminari. Could you maybe submit a PR with a test to demo the issue?

@smridge
Copy link

smridge commented Aug 22, 2020

I'm having this same issue after upgrading to grape-kaminari (0.3.0) for a non rails app but rather a grape app that uses ActiveRecord. The implementation is exactly comparable to @zaoldreck 's example above.

Error Message:

NoMethodError: undefined method `paginate' for #<Class:0x00007fa64c1250f8>

In config.ru

require 'grape'
require 'grape-kaminari'
require 'active_record'
require 'kaminari/activerecord'
require 'raven'
require 'rake'
...

I tried @bsodmike 's suggestion and no dice :/

Thoughts from anyone?

@bsodmike
Copy link

I tried @bsodmike 's suggestion and no dice :/

Thoughts from anyone?

@smridge can you try my suggestion with gem 'grape-kaminari', '~> 0.2.1'

@smridge
Copy link

smridge commented Aug 22, 2020

@bsodmike , good catch, I clearly missed that part in your initial suggestion 🙃 . After doing this, I don't even need Grape::API::Instance.include(Grape::Kaminari) when updating to 'grape-kaminari', '~> 0.2.1'...I'm guessing this is because it updates grape (1.4.0).

Updating to grape-kaminari (0.3.0) updates grape (1.3.3) due to grape (>= 1.0, != 1.4.0). When adding your suggestion for this version, this error occurs:

NameError: undefined local variable or method `base_instance' for Grape::API::Instance:Class
Did you mean?  base_instance?

which appears to be resolved in ruby-grape/grape#1946 (solved in grape v1.3.1 - I believe base off PR number. I also checked my local gem installation to make sure the method was there.)

So that's half solved in my opinion. Not sure why we can't update to the newest grape version?

@smridge
Copy link

smridge commented Aug 22, 2020

So that's half solved in my opinion. Not sure why we can't update to the newest grape version?

Oh I see, because the update was for version 0.3.0 which does not have the base_instance method.

So what's the proposed solution?

@zaoldreck
Copy link
Author

Please upgrade grape version and grape-kaminari

gem 'grape', '~> 1.5'
gem 'grape-kaminari', '~> 0.4.0'

@smridge

@smridge
Copy link

smridge commented Oct 16, 2020

@zaoldreck works like a charm! Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants