@@ -54,11 +54,14 @@ def active_admin_import(options = {}, &block)
5454 options . assert_valid_keys ( *Options ::VALID_OPTIONS )
5555
5656 options = Options . options_for ( config , options )
57- params_key = ActiveModel ::Naming . param_key ( options [ :template_object ] )
5857
5958 collection_action :import , method : :get do
6059 authorize! ( ActiveAdminImport ::Auth ::IMPORT , active_admin_config . resource_class )
61- @active_admin_import_model = options [ :template_object ]
60+ @active_admin_import_model = if options [ :template_object ] . is_a? ( Proc )
61+ options [ :template_object ] . call
62+ else
63+ options [ :template_object ]
64+ end
6265 render template : options [ :template ]
6366 end
6467
@@ -75,7 +78,12 @@ def active_admin_import(options = {}, &block)
7578 authorize! ( ActiveAdminImport ::Auth ::IMPORT , active_admin_config . resource_class )
7679 _params = params . respond_to? ( :to_unsafe_h ) ? params . to_unsafe_h : params
7780 params = ActiveSupport ::HashWithIndifferentAccess . new _params
78- @active_admin_import_model = options [ :template_object ]
81+ @active_admin_import_model = if options [ :template_object ] . is_a? ( Proc )
82+ options [ :template_object ] . call
83+ else
84+ options [ :template_object ]
85+ end
86+ params_key = ActiveModel ::Naming . param_key ( @active_admin_import_model . class )
7987 @active_admin_import_model . assign_attributes ( params [ params_key ] . try ( :deep_symbolize_keys ) || { } )
8088 # go back to form
8189 return render template : options [ :template ] unless @active_admin_import_model . valid?
0 commit comments