Code Monkey home page Code Monkey logo

Comments (5)

Fivell avatar Fivell commented on August 29, 2024

@sharshenov , what are you trying to achieve with csv_template ? How it can help?

from active_admin_import.

scarroll32 avatar scarroll32 commented on August 29, 2024

I think it is a good idea: a template of column names could be added which would allow

  1. Verification that the right number of columns are in the file
  2. Names for columns which can be used in later processing

A much larger feature would be the ability to specify types (or map them to actual table columns) and reject the row or whole file on a mismatch.

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

@seanfcarroll , any ideas with dsl example for this new feature ?

from active_admin_import.

workgena avatar workgena commented on August 29, 2024

@sharshenov , latest release has one of features you've requested.

Skip CSV-columns. Basically it allows you to specify what columns to take from CSV-file.

Take a look, and share your thoughts about this implementation. Is it enough for your needs?

from active_admin_import.

etozzato avatar etozzato commented on August 29, 2024

+1

I monkey-patched my temporary* solution as:

     collection_action :template, method: :get do
        respond_to do |format|
          csv_template = CSV.generate do |csv|
            csv << resource_class.column_names - %w[created_at updated_at].map do |attr|
              resource_class.human_attribute_name(attr, default: attr.to_s.titleize)
            end
          end
          format.csv do
            send_data csv_template,
                      filename: "#{resource_class}_template.csv",
                      type: 'application/csv',
                      disposition: 'inline'
          end
        end
      end

      action_item :import, only: :index, if: options[:if] do
        if authorized?(ActiveAdminImport::Auth::IMPORT, active_admin_config.resource_class)
          span do
            link_to(
              I18n.t('active_admin_import.import_model', plural_model: options[:plural_resource_label]),
              action: :import
            )
          end
          span do
            link_to(
              I18n.t('active_admin_import.template'),
              action: :template,
              format: :csv
            )
          end
        end
      end
  • I will look at how to whitelist only a subset of attributes for import and adapt the template accordingly

from active_admin_import.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.