I have a helper method for ActiveAdmin that defines some actions that are the same for all models.
In 'app / helpers / active_admin / import_helper.rb'
module ActiveAdmin module ImportHelper def self.included(base) base.instance_eval do action_item only: :index do link_to "Import", action: :import end collection_action :import do render "admin/import" end controller do def save_csvimport(item)
In 'app / admin / categories.rb'
ActiveAdmin.register Store::Category do include ImportHelper config.filters = false collection_action :importcsv, method: :post do save_csvimport "Category" end end
When loading the application, I get the following error:
app/helpers/active_admin/import_helper.rb:6:in `block in included': undefined method `action_item' for
How to define these methods in all "admin / *. Rb" files? (This import function is the same for all models.)
I am using ruby โโ2.0 and rails 4.
EDIT:
When I define ImportHelper in 'app / admin / import_helper.rb' as follows:
# Note no namespacing module ImportHelper def self.included(base) base.instance_eval do action_item only: :index do link_to "Import", action: :import end collection_action :import do render "admin/import" end controller do def save_csvimport(item)
And the category.rb category looks like this:
ActiveAdmin.register Store::Category do config.filters = false require_relative "./import_helper" include ImportHelper collection_action :importcsv, method: :post do save_csvimport "Category" end end
Everything works. However, this seems to me useless, since the import file should not be in "app / admin", and the require_relative call is not required.