Code Monkey home page Code Monkey logo

Comments (15)

Fivell avatar Fivell commented on August 29, 2024

@joshuaswilcox , can you show example of imported file, and resource #active_admin_import declaration?

from active_admin_import.

joshuaswilcox avatar joshuaswilcox commented on August 29, 2024

CSV

Billy,Corgan,[email protected],123456789,123456789,1,1,male

and declaration

active_admin_import :validate => false,
                        :template_object => ActiveAdminImport::Model.new(
                            :hint => "file will be imported with such header format: 'first_name','last_name','email','password', 'password_confirmation', 'team_id', 'age', 'gender'",
                            :csv_headers => ["first_name","last_name","email","password","password_confirmation","team_id","age","gender"]
                        ),
                        :batch_size => 1000

I was thinking I can probably call a before_import proc to encrypt the password before import

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

@joshuaswilcox , unfortunately I can't check it right now, because I have limited internet access, the one thing you can try is to use before_batch_import hook like in readme example, in this proc you should have access to import.csv_lines (lines to import) so you can try to change them in loop.

from active_admin_import.

joshuaswilcox avatar joshuaswilcox commented on August 29, 2024

@Fivell, thanks that was I was thinking. I'll report back

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

Also if you use default password, you can move it out of the file, and add it dynamically , I mean you can append value to each csv_line and also to csv_headers in before_batch_import.

from active_admin_import.

joshuaswilcox avatar joshuaswilcox commented on August 29, 2024

Ah yes that makes sense as well. So I called:

import.csv_lines[0][3] = User.new(:password => import.csv_lines[0][3]).encrypted_password

in the before_batch_import and it properly set the value I was looking for, but I get:

(PG::NotNullViolation: ERROR:  null value in column "created_at" violates not-null constraint

but my db definition just uses the normal t.timestamps. Any ideas?

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

@joshuaswilcox, try to set timestamps option.

active_admin_import :validate => false, :timestamps=> true, .....

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

@joshuaswilcox , so does it finally work ?

from active_admin_import.

joshuaswilcox avatar joshuaswilcox commented on August 29, 2024

Yes, brilliant, thanks for the help!

from active_admin_import.

andymilk avatar andymilk commented on August 29, 2024

@joshuaswilcox do you have the full import block for this? I'm having a similar problem, but getting this error: Error: Missing column for value at index 2

from active_admin_import.

joshuaswilcox avatar joshuaswilcox commented on August 29, 2024

sure

  active_admin_import :validate => false,
                            :before_batch_import => proc { |import|
                              import.csv_lines[0][3] = User.new(:password => import.csv_lines[0][3]).encrypted_password
                            },
                            :template_object => ActiveAdminImport::Model.new(
                                :hint => "file will be imported with such header format: 'first_name','last_name','email','password', 'team_id', 'age', 'gender'"
                            ),
                            :timestamps=> true,
                            :batch_size => 1000

from active_admin_import.

asecondwill avatar asecondwill commented on August 29, 2024

I had a bit of trouble with this till the penny dropped to change the header to encrypted_password.

so

first_name,last_name,email,encrypted_password
joe,blogs,[email protected],12345678


  active_admin_import :validate => false,
                            :before_batch_import => proc { |import|
                             # binding.pry                              
                              import.csv_lines[0][3] = User.new(:password => import.csv_lines[0][3]).encrypted_password
                            },
                            after_batch_import: ->(importer) {
                             #the same
                            # binding.pry
                            },
                            :template_object => ActiveAdminImport::Model.new(
                                :hint => "file will be imported with the header format: 'first_name','last_name','email','password'"
                            ),
                            :timestamps=> true,
                            :batch_size => 1000 

from active_admin_import.

kyreeves avatar kyreeves commented on August 29, 2024

@asecondwill @joshuaswilcox

How would you do this if you had multiple attributes that were encrypted? I can't seem to figure it out.

from active_admin_import.

kyreeves avatar kyreeves commented on August 29, 2024

@Fivell do you have any suggestions?

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

@kyreeves , there is an example how to change data while importing https://github.com/activeadmin-plugins/active_admin_import/wiki/change-columns-on-the-fly-by-association

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.