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

Already on GitHub? Sign in to your account

Incorrect find query is used for Mongoid embedded documents #48

monfresh opened this Issue Jul 10, 2013 · 6 comments


None yet
5 participants


I'm using activeadmin-mongoid with Rails 3.2.13 and Mongoid 3.1.4, and I'm trying to view an embedded document in the admin interface, but I get Document(s) not found for class ApiApplication with id(s) 51dcba...

I have a User resource that embeds_many api_applications, and it looks like activeadmin-mongoid is using ApiApplication.find, but in Mongoid, that won't work. If a User embeds_many api_applications, you have to do user.api_applications.find(id)

My admin/users.rb show snippet:

show :title => :name do |user|
  attributes_table do
    row :name
    row :email

  panel "API Applications" do
    table_for user.api_applications do |t|
      t.column("Name") do |api_application|
        link_to api_application.name,
          admin_user_api_application_path(user, api_application)

My admin/api_applications.rb has this:

ActiveAdmin.register ApiApplication do
  belongs_to :user

When I view the show page for a particular user, it is displaying the correct ApiApplication for that user, but when I click on the link that should take me to the show view for the ApiApplication, I get that document not found error.

Note that this works fine if I use has_many and belongs_to in my Mongoid models instead.

Is this a known issue with embedded documents?

After applying @mabotelh's solution in issue #38, I am now able to view the embedded document. However, when I try to edit it, it fails with the same error as before.

Did you end up finding a solution to this issue?

monfresh commented Aug 3, 2013

I have not, so I switched to rails_admin, which supports Mongoid quite nicely.


elia commented Aug 9, 2013

I think the solution resides in redefining the resource finder in the controller. I'll keep this open until a solution lands on master.

is someone working on this?


elia commented Sep 1, 2014

Not me. Actually tarting for now I'm looking for a maintainer, will update the readme with details.

@boie0025 boie0025 closed this Jun 6, 2017

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