Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading all records of a paginated resource in ActiveAdmin

Tags:

activeadmin

I am trying to use the collection action "download_csv" already present in Active Admin to download all the records of a resource. However, the action only downloads the contents of the present page. As I have paginated the resource, the data needs to be downloaded from all the pages. Any suggestions on how I can approach this problem ?

like image 258
Saiesh Avatar asked Dec 30 '25 13:12

Saiesh


2 Answers

Just for future googlers. My fix (working for the current Master 1.0.0pre) is to add the following to config/initializers/active_admin.rb:

module ActiveAdmin
  class ResourceController
    module DataAccess
      # needed for current active admin master
      def max_per_page
        30_000
      end

      def per_page
        return 30_000 if %w(text/csv application/xml application/json).include?(request.format)

        return max_per_page if active_admin_config.paginate == false

        @per_page || active_admin_config.per_page
      end
    end
  end
end

Replace the max as needed. This works for csv, xml and json downloads.

like image 153
Sebastian Krog Avatar answered Jan 06 '26 09:01

Sebastian Krog


This answer might be a little late but hopefully it can help somebody.

Here is how I have this working in my current app:

csv do
  ModelName::ATTR_ADMIN_EXPORT.each do |sym|
    column sym
  end
end

And in the model I have ATTR_ADMIN_EXPORT defined like this:

ATTR_ADMIN_EXPORT = [:name, :created_at]

Let me know if this works for you!

like image 22
Josh Rumbut Avatar answered Jan 06 '26 09:01

Josh Rumbut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!