undefined method `per_page_kaminari' for Models inheriting from Models in gems #1828

Closed
ktaragorn opened this Issue Nov 5, 2013 · 19 comments

Projects

None yet

5 participants

@ktaragorn

A bit of a twister of a title. Let me explain

In our project, we have modularized a bunch of our models into its own gem, and use this gem in our main project. We have Models in our main project which inherit from Models in this gem.

When trying to access these models on Rails Admin, I get the following error.
I also get this error when going into the "History" tab for most if not all models.

I am using

rails_admin (0.4.4)
safe_yaml (0.8.6)
haml (3.1.8)

I am stuck with the old version cuz of haml, and would rather not upgrade if possible (I tried and failed)

undefined method `per_page_kaminari' for #<ActiveRecord::Relation:0x007fb57674c588>

activerecord (3.2.12) lib/active_record/relation/delegation.rb:45:in `method_missing'
rails_admin (0.4.4) lib/rails_admin/adapters/active_record.rb:46:in `all'
rails_admin (0.4.4) app/controllers/rails_admin/main_controller.rb:140:in `get_collection'
rails_admin (0.4.4) app/controllers/rails_admin/main_controller.rb:39:in `list_entries'
rails_admin (0.4.4) lib/rails_admin/config/actions/index.rb:30:in `block (2 levels) in <class:Index>'
(eval):8:in `instance_eval'
(eval):8:in `index'
actionpack (3.2.12) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.12) lib/abstract_controller/base.rb:167:in `process_action'
@ktaragorn

Is there anything I can do to debug or better understand this issue? I really want to use this gem but this error is blocking like half our models.

@mshibuya
Collaborator

Can we take a look at your Gemfile?
I assume you're using kaminari/will_paginate conflict workaround suggested in Wiki. Where do you place it and what does it contain?

@ktaragorn

Ah interesting.. Why didnt I think of this. Let me look into it.

Currently the 3 gems are in this order

gem "paper_trail", "~> 2.7.2" #to track changes to models
...
gem 'rails_admin'
...
...
...
gem 'common_library', :git =>...

Hmm..

On 14 November 2013 11:40, Mitsuhiro Shibuya notifications@github.comwrote:

Can we take a look at your Gemfile?
I assume you're using kaminari/will_paginate conflict workaround suggested
in Wiki https://github.com/sferik/rails_admin/wiki/Troubleshoot. Where
do you place it and what does it contain?


Reply to this email directly or view it on GitHubhttps://github.com/sferik/rails_admin/issues/1828#issuecomment-28457105
.

@ktaragorn

My Kaminari workaround is the below code in config/initializers/kaminari.rb

Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari
end

On 14 November 2013 15:34, Karthik T karthikt.holmes@gmail.com wrote:

Ah interesting.. Why didnt I think of this. Let me look into it.

Currently the 3 gems are in this order

gem "paper_trail", "~> 2.7.2" #to track changes to models
...
gem 'rails_admin'
...
...
...
gem 'common_library', :git =>...

Hmm..

On 14 November 2013 11:40, Mitsuhiro Shibuya notifications@github.comwrote:

Can we take a look at your Gemfile?
I assume you're using kaminari/will_paginate conflict workaround
suggested in Wikihttps://github.com/sferik/rails_admin/wiki/Troubleshoot.
Where do you place it and what does it contain?


Reply to this email directly or view it on GitHubhttps://github.com/sferik/rails_admin/issues/1828#issuecomment-28457105
.

@ktaragorn

I reversed the order of the 3 gems, still same error

On 14 November 2013 15:40, Karthik T karthikt.holmes@gmail.com wrote:

My Kaminari workaround is the below code in config/initializers/kaminari.rb

Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari
end

On 14 November 2013 15:34, Karthik T karthikt.holmes@gmail.com wrote:

Ah interesting.. Why didnt I think of this. Let me look into it.

Currently the 3 gems are in this order

gem "paper_trail", "~> 2.7.2" #to track changes to models
...
gem 'rails_admin'
...
...
...
gem 'common_library', :git =>...

Hmm..

On 14 November 2013 11:40, Mitsuhiro Shibuya notifications@github.comwrote:

Can we take a look at your Gemfile?
I assume you're using kaminari/will_paginate conflict workaround
suggested in Wikihttps://github.com/sferik/rails_admin/wiki/Troubleshoot.
Where do you place it and what does it contain?


Reply to this email directly or view it on GitHubhttps://github.com/sferik/rails_admin/issues/1828#issuecomment-28457105
.

@ktaragorn

I just came across this bug - kaminari/kaminari#119. Although I have 0.14.1 which should have fixed this, perhaps the fix doesnt work with the workaround?

@ktaragorn

No go, but it is looking like more of a Kaminari issue, especially in light of kaminari/kaminari#473

@yuki24
yuki24 commented Nov 20, 2013

@ktaragorn I think all of the models you have in your own gem are loaded before config/initializers/kaminari.rb is loaded. Try loading the kaminari config first and check if the models have #per_page_kaminari method.

@ktaragorn

@yuki24 Thanks for responding, I will try the master branch as you suggested in a different branch, and this suggestion and get back soon

@ktaragorn

@yuki24 I was able to get your suggestion to work (a bit ugly, but works) with 0.14.1. master of kaminari seems broken unfortunately for this use case..

@ktaragorn ktaragorn closed this Nov 20, 2013
@ktaragorn

What I i did was add ,require: false to each of the gems in question, and then manually required those in kaminari.rb, the initializer

@hspinks
hspinks commented Dec 17, 2013

@ktaragorn I am running into the same issue. Can you please advise a bit further on how to fix?

My gem versions:
rails_admin: 0.4.9
kaminari: 0.15.0
safe_yaml: 0.9.7
haml: 4.0.4
paper_trail and common_library are not installed

I'm using the known fix for the conflict with will_paginate and kaminari, as well as the known fix for twitter-bootstrap-rails.

I can't tell completely exactly which gems you were talking about in this last comment, but it seems like some of the gems that might be causing the problem aren't present in my app. If you have any ideas, I would appreciate it!

@ktaragorn

@hspinks Are you having my exact problem where i have base classes coming from gems? If so the fix is to add ,require: false to each of the gems which supply said base classes, like so

gem "paper_trail", require: false

And at the bottom of the initializer for kaminari, in kaminari.rb, add lines which require each of the above troublesome gems, like so

...
end

require "paper_trail"

What you need to figure out first is which gems are adding these active record classes or base classes, then you can do as above.

@hspinks
hspinks commented Dec 18, 2013

@ktaragorn thanks for the tips. I was having the identical problem where my base class was coming from gems. Your fix sounds reasonable, but I realized that we had removed all pagination within the app and no longer needed the will_paginate gem. I ended up simply removing that gem as well as the fix for the kaminari / will_paginate conflict, and no longer had any issue. Thanks!

@hspinks
hspinks commented Dec 18, 2013

@ktaragorn just tested your fix on the original code (before I removed will_paginate). Result: success!

I actually don't mind using kaminari rather than will_paginate, so I will go back to my original solution of just getting rid of the conflict, but good to know that it worked.

@yuki24
yuki24 commented Dec 18, 2013

@hspinks @ktaragorn I guess it's a bit late to tell you this, but kaminari 0.15.0 has a bug that page_method_name option, which active_admin uses, has no effect: kaminari/kaminari#481
It has been fixed on master on GitHub, so try it out if you still see this issue.

@ktaragorn

Hi @yuki24, I am not sure if that is the same issue as this, since I am still on 0.14.1, and it works for all models that originate in the main project itself

@hspinks great that you dont have to hack it :P

@Ricardonacif

I'm still getting this issue.

@graysonwright graysonwright referenced this issue in thoughtbot/administrate Nov 5, 2015
Closed

Issue: undefined method `per' #158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment