From 13f2e3b1fc0bdfce8f23614eef45f187f60ed498 Mon Sep 17 00:00:00 2001 From: Cyril Mougel Date: Tue, 2 May 2017 08:30:51 +0000 Subject: [PATCH] Allow to change active-admin namespace --- README.md | 6 ++++++ lib/active_admin/async_export.rb | 8 ++++++++ lib/active_admin/async_export/async_export_mailer.rb | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f127af6..ae8f296 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,12 @@ In an initializer, include a line like the following: ActiveAdmin::AsyncExport.from_email_address = 'admin@topshelfclothes.com' +### Change the active admin namespace + +If your namespace of active-admin is not Admin you can change it. + + ActiveAdmin::AsyncExport.controller_namespace = 'Myadmin' + ## Contributing 1. Fork it diff --git a/lib/active_admin/async_export.rb b/lib/active_admin/async_export.rb index 160feea..7b771b1 100644 --- a/lib/active_admin/async_export.rb +++ b/lib/active_admin/async_export.rb @@ -14,5 +14,13 @@ def self.from_email_address=(address) def self.from_email_address @from_email_address || 'admin@example.com' end + + def self.controller_namespace=(namespace) + @controller_namespace = namespace + end + + def self.controller_namespace + @controller_namespace || 'Admin' + end end end diff --git a/lib/active_admin/async_export/async_export_mailer.rb b/lib/active_admin/async_export/async_export_mailer.rb index ed90c17..d54f54c 100644 --- a/lib/active_admin/async_export/async_export_mailer.rb +++ b/lib/active_admin/async_export/async_export_mailer.rb @@ -4,7 +4,7 @@ class AsyncExportMailer < ActionMailer::Base def csv_export(admin_email, model_name, params_json) params = JSON.parse(params_json) - controller = Kernel::qualified_const_get("Admin::#{model_name}sController").new + controller = Kernel::qualified_const_get("#{ActiveAdmin::AsyncExport.controller_namespace}::#{model_name}sController").new controller.send('params=', params) config = controller.send(:active_admin_config) @@ -19,7 +19,7 @@ def controller.find_collection(options = {}) :pagination, :collection_decorator ] - + collection = scoped_collection collection_applies(options).each do |applyer| collection = send("apply_#{applyer}", collection)