Sha256: 0b81a42774bc8848cfb1561ca50ce1dc6d0585e847625e2fcdc4e03108e3bdfe
Contents?: true
Size: 445 Bytes
Versions: 1
Compression:
Stored size: 445 Bytes
Contents
require 'csv' class CsvDb class << self def convert_save(model_name, 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) else target_model.create!(row.to_hash) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_admin_importable-1.1.1 | app/models/csv_db.rb |