Reputation: 1
I'm new to Ruby on Rails and I have been struggle with this for a couple of days know.
I have an ActiveAdmin page, that is pulling information from different Db's.
I created a couple of scope sections to handle different categories. The code of the ActiveAdmin looks something similar to this:
ActiveAdmin.register MyItem do
scope :all
scope :first_db do |myitem|
myitem.where(deleted: false)
end
scope :FromDBs, show_count=>true do |myitem|
Kaminari.paginate_array(MyItem.get_from_dbs).page(params[:page])
end
index do
column :name
column :value
end
Now, the issue I'm having, is with scope "FromDBs". It shows on the top as the record count the amount of records as 25 (that is my page size for pagination) and not the total amount of records in the array. If I go to the footer of the page, the "Next" button shows the correct amount of records.
So, my question would be, how I can do to make the "scope" section to show the amount of records on the array and not the amount of record per page.
At some extend I tried to follow some of the recomendation from here, but not really working for me. That is why I'm using Kaminari to be able to paginate the array.
Thanks for any pointer.
Upvotes: 0
Views: 898
Reputation: 3807
You don't necessarily define your scopes in an ActiveAdmin resource block, Instead you want your scope definitions in your model class. I have a similar setup like below:
class Manager < ActiveRecord::Base
scope :active, -> { where deleted_at: nil }
scope :inactive, -> { where.not deleted_at: nil }
...
end
ActiveAdmin.register Manager do
scope :active, default: true
scope :inactive
end
This handles records counts accordingly.
Upvotes: 2