Skip to content
11 changes: 9 additions & 2 deletions lib/active_admin_csv_import/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def csv_importable(options = {})
collection_action :import_csv do
@columns = columns
@required_columns = required_columns
@collection_path = parent ? collection_path(params.slice("#{parent.class.name.underscore}_id")) : collection_path
@collection_path = parent ? collection_path({"#{parent.class.name.underscore}_id" => parent.id}) : collection_path

@post_path = options[:path].try(:call)
@post_path ||= @collection_path + '/import_rows'
Expand All @@ -54,7 +54,10 @@ def csv_importable(options = {})
row_number = row_params.delete('_row')

resource = existing_row_resource(options[:import_unique_key], row_params)
resource ||= active_admin_config.resource_class.new
resource ||= build_row_resource

# controller before create callback
resource = before_create(resource) if respond_to? :before_create
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this happen as part of build_row_resource?


unless update_row_resource(resource, row_params)
@failures << {
Expand Down Expand Up @@ -88,6 +91,10 @@ def update_row_resource(resource, params)
resource.save
end

def build_row_resource
end_of_association_chain.new
end

def existing_row_resource(lookup_column, params)
return unless lookup_column

Expand Down