krhorst / active_admin_importable

CSV imports for Active Admin resources
MIT License
53 stars 55 forks source link

Better errors and allow updates #14

Open ghost opened 11 years ago

ghost commented 11 years ago

This started as a response to Issue #5 and ended up including some other features that I find useful for my own projects:

karlwilbur commented 9 years ago

Rather that override create! it seems that this would be a good candidate to utilize the passed in &block ...something like:

active_admin_importable do |model, hash|
  object = model.find_by(id: row[:id]) || model.new
  model.column_names.each do |key|
    key = key.to_sym
    if hash.keys.include?(key)
      value = hash[key]
      object.send "#{key}=", value if value != nil
    end
  end
  object.save ? true : object.errors
end