Skip to content

Commit

Permalink
replacing resource_name with resource_class
Browse files Browse the repository at this point in the history
  • Loading branch information
krhorst committed Apr 30, 2013
1 parent 1dd1e3e commit d1247e0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions app/models/csv_db.rb
@@ -1,14 +1,13 @@
require 'csv'
class CsvDb
class << self
def convert_save(model_name, csv_data, &block)
def convert_save(target_model_klass, csv_data, &block)
csv_file = csv_data.read
target_model = model_name.pluralize.classify.constantize
CSV.parse(csv_file, :headers => true, header_converters: :symbol ) do |row|
if(block_given?)
block.call(target_model, row.to_hash)
block.call(target_model_klass, row.to_hash)
else
target_model.create!(row.to_hash)
target_model_klass.create!(row.to_hash)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin_importable/dsl.rb
Expand Up @@ -10,7 +10,7 @@ def active_admin_importable(&block)
end

collection_action :import_csv, :method => :post do
CsvDb.convert_save(active_admin_config.resource_name.to_s, params[:dump][:file], &block)
CsvDb.convert_save(active_admin_config.resource_class, params[:dump][:file], &block)
redirect_to :action => :index, :notice => "#{active_admin_config.resource_name.to_s} imported successfully!"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin_importable/version.rb
@@ -1,3 +1,3 @@
module ActiveAdminImportable
VERSION = "1.1.1"
VERSION = "1.1.2"
end

0 comments on commit d1247e0

Please sign in to comment.