activeadmin / activeadmin-mongoid

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

Mongoid records embedded in resource in active admin are not displayed #91

Closed mitchenkod closed 10 years ago

mitchenkod commented 10 years ago

I have the following models

class User::ActiveAdmin::Partner < User::ActiveAdmin::Base
  embeds_many :bonuses, class_name: 'User::Bonus'
end 

and

class User::Bonus
  include Mongoid::Document
  embedded_in :partner, class_name: 'User::ActiveAdmin::Partner'
end

and then I register Bonuses in Active Admin

    ActiveAdmin.register User::Bonus, as: 'Bonuses' do
      config.filters = false

      permit_params :number, :order_id

      controller do
        def scoped_collection
          if current_admin_user.is_a? User::ActiveAdmin::Partner
            current_admin_user.bonuses.page(params[:page]).per(10)
          else
            super
          end
        end

      end

the collection is not empty (I have created a couple of bonuses), but in ActiveAdmin index page I see, that there are NO BONUSES. And nothing I can do to make it displayed properly. I have noticed, that User::Bonus table is empty, even if a partner does have any, but as I know, this is the way it works, and this is OK. So how can I make my table to be displayed? Thanks.

max-konin commented 10 years ago

The problem in method ActiveAdmin::Helpers::Collection#collection_size. You are using old version of activeadmin-mongoid. Try update activeadmin-mongoid.

max-konin commented 10 years ago

In rails4 branch, collection_size isn't correct. You should override this method in your app like here: https://github.com/elia/activeadmin-mongoid/blob/master/lib/active_admin/mongoid/helpers/collection.rb