Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Incorrect find query is used for Mongoid embedded documents #48

Open
monfresh opened this Issue · 6 comments

4 participants

@monfresh

Hi,

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
  end

  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)
      end
    end
  end
end

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?

@monfresh

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.

@mrjlynch

Did you end up finding a solution to this issue?

@monfresh

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

@elia
Owner

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

@sapienza

is someone working on this?

@elia
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.