export Blogs
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
Kiprosh is now part of LawLytics
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
In one of my project I would like to dump and export some information into a csv file. I have produced an easy script to do that. require 'csv' file = "#{Rails.root}/public/user_data.csv" products = Product.order(:first_name) headers = ["Product ID", "Name", "Price", "Description"] CSV.open(file, 'w', write_headers: true, headers: headers) do |writer| products.each do |product| writer << [product.id, product.name, product.price, product.description] end end Here is what the above snippet does: Require the CSV library, since we'll be manipulating
activeadmin-axlsx gem [activeadmin-axlsx][1] gem is very useful to download or export excel records from active admin. It provides "XLSX" links to download Active Admin resources. We can use this gem by include this line in gem file: gem 'activeadmin-axlsx' then run: bundle install Now all resources of active admin index page include a 'XLSX' link. There is some example to customize 'activeadmin-axlsx'. Remove unnecessary column: app/admin/orders.rb ActiveAdmin.register Order do config.xlsx_builder.delete_columns :created_at, :updated_at end Change the style of column header: app/admin/orders.rb ActiveAdmin.register Order do