Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails active admin csv outputs all results rather than selected

Im using active admin and when i export to csv json or xml. I get all results rather than checked results. Could anyone help me fix this.

So my Order.rb file for active admin is.

ActiveAdmin.register Order do
  scope :not_completed_orders

  action_item :add do
    link_to "Get Manifest", "/admin/orders.csv"
  end

  index do
    selectable_column
    column :id
    column :user
    column :name
    column :delivery_name
    column :complete
    column :delivery_address1
    column :service
    column :insurance
    actions
  end

  csv do
    column :name
    column :delivery_name
    column :id 
  end
  # See permitted parameters documentation:
  # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
  #
  # permit_params :list, :of, :attributes, :on, :model
  #
  # or
  #
  permit_params do
    permitted = [:email ,:country ,:city ,:postcode, :address_line_2, :address_line_1 ,:user_id, :name, :delivery_name, :company_name, :delivery_address1, :delivery_address2, :delivery_address3, :delivery_city, :delivery_postcode, :delivery_country, :phone, :package_contents, :description_content, :restricted_items, :terms_conditions, :insurance, :contents_value, :cf_reference, :reference_number, :complete]
    permitted
  end
end
# completed_at

When i click get manifest or export to csv in active admin. I wish to get the checked results. Rather than all of the results.

like image 764
Morphasis Avatar asked Aug 05 '15 10:08

Morphasis


1 Answers

The ActiveAdmin download links are only exporting all entries.

But you can pass a filter with the selected ids via a batch action:

batch_action :export do |ids|
  redirect_to "/admin/orders.csv?q[id_in][]=" + ids.join("&q[id_in][]=")
end

NOTE: keep in mind that the URL can be to long for a request with to many selected items.

like image 130
Timo Schilling Avatar answered Sep 30 '22 02:09

Timo Schilling