Module: ActiveAdmin::Axlsx::ResourceControllerExtension
- Defined in:
- lib/active_admin/axlsx/resource_controller_extension.rb
Class Method Summary collapse
Instance Method Summary collapse
- #index_with_xlsx(options = {}, &block) ⇒ Object
- #per_page_with_xlsx ⇒ Object
-
#xlsx_filename ⇒ Object
Returns a filename for the xlsx file using the collection_name and current date such as ‘my-articles-2011-06-24.xlsx’.
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 |
# File 'lib/active_admin/axlsx/resource_controller_extension.rb', line 4 def self.included(base) base.send :alias_method_chain, :per_page, :xlsx base.send :alias_method_chain, :index, :xlsx base.send :respond_to, :xlsx end |
Instance Method Details
#index_with_xlsx(options = {}, &block) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/active_admin/axlsx/resource_controller_extension.rb', line 10 def index_with_xlsx(={}, &block) index_without_xlsx() do |format| format.xlsx do xlsx = active_admin_config.xlsx_builder.serialize(collection) send_data xlsx.to_stream.read, :filename => "#{xlsx_filename}", :type => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" end end end |
#per_page_with_xlsx ⇒ Object
19 20 21 22 23 24 |
# File 'lib/active_admin/axlsx/resource_controller_extension.rb', line 19 def per_page_with_xlsx if request.format == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' return max_csv_records end per_page_without_xlsx end |
#xlsx_filename ⇒ Object
Returns a filename for the xlsx file using the collection_name and current date such as ‘my-articles-2011-06-24.xlsx’.
28 29 30 |
# File 'lib/active_admin/axlsx/resource_controller_extension.rb', line 28 def xlsx_filename "#{resource_collection_name.to_s.gsub('_', '-')}-#{Time.now.strftime("%Y-%m-%d")}.xlsx" end |