activeadmin / activeadmin-mongoid

ActiveAdmin hacks to support Mongoid
MIT License
192 stars 210 forks source link

Force activeadmin to use Mongoid when ActiveRecord is loaded as well #106

Closed mklnz closed 6 years ago

mklnz commented 7 years ago

I've been trying the rails5-mongoid6 branch and I have a project with both Mongoid and ActiveRecord for some legacy models using a different database.

Normally without activeadmin there is no problem, each model uses its own ORM. However when I add in activeadmin-mongoid, it automatically assumes it's AR and not Mongoid and causes this error:

undefined method `ransack' for #<Mongoid::Criteria:0x007f7f826df228>

If I remove the require "active_record/railtie" line from application.rb, ActiveAdmin works but the rest of my app is broken.

Is there a way to force active_admin to use Mongoid mode even if AR is loaded?

boie0025 commented 7 years ago

Hi @mklnz

There's currently no way to explicitly tell the gem that you're using Mongoid, it assumes that if it's installed you're not also including AR.

I've never tried this specific scenario, but I am a bit surprised by the error. Will you please provide a backtrace on this error? A sample application that recreates this error would also be helpful. Maybe there's a workaround we can come up with for this case.

mklnz commented 7 years ago

Sorry for the late reply. Here is a demo app I've created with AR loaded but not used. In my real app most models are Mongoid except 1 or 2 which are subclassed from AR. However having AR loaded is enough to cause ransack errors by clicking the Post model in /admin

https://github.com/mklnz/ar-mongoid-active-admin-test

boie0025 commented 7 years ago

Great, I was able to get this running and re-create the error you're talking about. I'll see what I can come up with for a solution.

boie0025 commented 6 years ago

@mklnz At this time, I don't think we'll be able to support AR + Mongoid in the same application. If you have the time to write a shim or make and test the change to this repo, please do.