Giter Club home page Giter Club logo

Comments (43)

Fivell avatar Fivell commented on July 30, 2024

@spurdow, can you show your models BusImport and Bus

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

its in here actually

https://github.com/jochun/lockout-ror/blob/master/db/migrate/20150704163947_create_bus.rb

the BusImport is stripped down of bus
like below:

        t.string     :name
        t.integer    :btype
        t.text       :reg_no
        t.text       :body_no
        t.text       :plate_no
        t.integer    :capacity
        t.timestamps null: false

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow , what about BusImport table ?

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

@Fivell its just the same but without relationship only necessary fields for importing...

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

@Fivell anyway, is there any way i could log the debug?

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow , application development.log or production.log depends on your env . Here

Rails.logger.error(I18n.t('active_admin_import.file_error', message: e.message))

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

btw, did you try validate: false ?

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

yeah tried both false and true... I dont fully understand what it really validates.

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

is my csv file wrong? or is there some options im missing?

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow , show me your development logs for this request.

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow , your csv seems valid

 puts csv
"name";"btype";"reg_no";"body_no";"plate_no";"capacity"
"BUS1";"1";"REGNO-xxx-xxxx";"BODY NO";"PLATE-XXX";"15"
"BUS2";"0";"REGNO-xxx-xxxx";"BODY NO";"LPATE-xxx";"15"
"BUS3";"1";"REGNO-xxx-xxxx";"BODY NO";"PLATE-XXX";"15"
=> nil
irb(main):016:0> arr_of_arrs = CSV.parse(csv,col_sep: ';')
=> [["name", "btype", "reg_no", "body_no", "plate_no", "capacity"], ["BUS1", "1", "REGNO-xxx-xxxx", "BODY NO", "PLATE-XXX", "15"], ["BUS2", "0", "REGNO-xxx-xxxx", "BODY NO", "LPATE-xxx", "15"], ["BUS3", "1", "REGNO-xxx-xxxx", "BODY NO", "PLATE-XXX", "15"]]

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow, just noticed you're using 2.1.2
try master branch gem "active_admin_import" , github: "activeadmin-plugins/active_admin_import"
give me a hint if you still have problems

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

still the same :'(

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

ill push my new commit today, i hope you will have the time to look it up.

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

@Fivell how do I show the logs only for active admin import?. I dont quiet get it.

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow , launch your app in development mode, make an import and capture new lines from development.log

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

oh so its already default to log in development sorry, My bad. Okay ill post anything I deem wrong.

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

Started POST "/admin/buses/do_import" for 127.0.0.1 at 2016-03-04 21:41:14 +0800
Processing by Admin::BusesController#do_import as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"FVUKXS8oxknnBdBgoG6uN/YOC4y8KMisn3icnvbUvVVDmlqpro1UmXWm5X54gEtMSTnvVtvSx6pAH5PovlX2sg==", "active_admin_import_model"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x0000000de6a3e0 @tempfile=#Tempfile:C:/Users/DAVIDL~1/AppData/Local/Temp/RackMultipart20160304-6960-sixmtq.csv, @original_filename="buses (1).csv", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name="active_admin_import_model[file]"; filename="buses (1).csv"\r\nContent-Type: application/octet-stream\r\n">}, "commit"=>"Import"}
AdminUser Load (1.0ms) SELECT admin_users.* FROM admin_users WHERE admin_users.id = 5 ORDER BY admin_users.id ASC LIMIT 1

AdminUser Load (1.0ms) SELECT admin_users.* FROM admin_users WHERE admin_users.email = '[email protected]' ORDER BY admin_users.id ASC LIMIT 1
#AdminUser:0x0000000d1e37c0
Subscription Exists (1.0ms) SELECT 1 AS one FROM subscriptions WHERE subscriptions.company_id = 3 LIMIT 1
Subscription Load (0.0ms) SELECT subscriptions.* FROM subscriptions WHERE subscriptions.company_id = 3 ORDER BY created_at DESC LIMIT 1
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/bundler/gems/active_admin_import-8a7f300c94a4/app/views/admin/import.html.erb within layouts/active_admin (6.0ms)
Completed 200 OK in 543ms (Views: 528.0ms | ActiveRecord: 3.0ms)

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow , send "buses (1).csv" file to my email

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

Ive sent u an email

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

This is my current setup

  active_admin_import validate: true,
                      csv_options: {col_sep: ";" },
                      resource_class: BusImport ,  # we import data into another resource
                      # before_import: proc{ .delete_all },
                      after_import: proc{
                        Bus.transaction do
                          Bus.connection.execute("INSERT INTO buses (name,btype,regno,body_no,plate_no,capacity) (SELECT name,btype,regno,body_no,plate_no,capacity FROM bus_imports)")
                        end
                      },
                      back: proc { config.namespace.resource_for(Bus).route_collection_path } # redirect to post index

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

Gemfile

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use mysql as the database for Active Record
gem 'mysql2'
# Active Admin
gem 'activeadmin', github: 'activeadmin'

gem 'devise' ,'~> 3.2'

gem "active_admin_import" , github: 'activeadmin-plugins/active_admin_import'

gem 'active_admin_datetimepicker'

# Use SCSS for stylesheets

gem "letter_opener"
gem 'gmaps4rails' , '~> 1.5.6'
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
gem 'draper', '~> 1.3'
gem 'coffee-script-source', '1.8.0'
# bundle update coffee-script-source
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem "just-datetime-picker"
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs wit
# h ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'cancan' ,'1.6.10'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'geocoder'



gem 'capistrano'

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow , I cloned your application and uploaded your file

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024
Started POST "/admin/buses/do_import" for ::1 at 2016-03-04 16:55:11 +0200
Processing by Admin::BusesController#do_import as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"7lrDzsYroboNGoPec40aO82qlO5xuPxgy+WlM8mAIfjUcMU6rCpdIpLNiZ2Lhxp2Eh4ycIadaFpA8ZRsVYH3YQ==", "active_admin_import_model"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x007fb16543a9b8 @tempfile=#<Tempfile:/var/folders/g8/1r7jmb011_x7c20kd45dfb1h0000gn/T/RackMultipart20160304-98171-1c0v6rf.csv>, @original_filename="buses (1).csv", @content_type="text/csv", @headers="Content-Disposition: form-data; name=\"active_admin_import_model[file]\"; filename=\"buses (1).csv\"\r\nContent-Type: text/csv\r\n">}, "commit"=>"Import"}
  AdminUser Load (0.2ms)  SELECT  `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 3  ORDER BY `admin_users`.`id` ASC LIMIT 1
   (0.1ms)  BEGIN
   (0.3ms)  SHOW VARIABLES like 'max_allowed_packet';
  Class Create Many Without Validations Or Callbacks (0.5ms)  INSERT INTO `bus_imports` (`name`,`btype`,`reg_no`,`body_no`,`plate_no`,`capacity`,`created_at`,`updated_at`) VALUES ('BUS1',1,'REGNO-xxx-xxxx','BODY NO','PLATE-XXX',15,'2016-03-04 14:55:11','2016-03-04 14:55:11'),('BUS2',0,'REGNO-xxx-xxxx','BODY NO','LPATE-xxx',15,'2016-03-04 14:55:11','2016-03-04 14:55:11'),('BUS3',1,'REGNO-xxx-xxxx','BODY NO','PLATE-XXX',15,'2016-03-04 14:55:11','2016-03-04 14:55:11') ON DUPLICATE KEY UPDATE `bus_imports`.`updated_at`=VALUES(`updated_at`)
   (0.4ms)  COMMIT
   (0.1ms)  BEGIN
   (1.4ms)  INSERT INTO buses (name,btype,regno,body_no,plate_no,capacity) (SELECT name,btype,regno,body_no,plate_no,capacity FROM bus_imports)
Mysql2::Error: Unknown column 'regno' in 'field list': INSERT INTO buses (name,btype,regno,body_no,plate_no,capacity) (SELECT name,btype,regno,body_no,plate_no,capacity FROM bus_imports)
   (0.3ms)  ROLLBACK
Error: Mysql2::Error: Unknown column 'regno' in 'field list': INSERT INTO buses (name,btype,regno,body_no,plate_no,capacity) (SELECT name,btype,regno,body_no,plate_no,capacity FROM bus_imports)

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

2016-03-04_1655

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

aww how did you get it to error message like that?, I always get Invalid Csv

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

Ive updated it , its wrong it should be reg_no

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

bus-csv

I always get this error. What sdk are you using?

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow , looks like your browser dosn't sent correct mime type
Here is valdiation
https://github.com/activeadmin-plugins/active_admin_import/blob/master/lib/active_admin_import/model.rb#L102

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

Parameters: {"utf8"=>"✓", "authenticity_token"=>"zT7lA7DM5YrHN9fWVo9Q9HcuU3WAgPywljdsKjiMf9gzfe3V5Y4LsfnUxE4PBR3/99ZetdnE0DV0T+pnndKnOw==", "active_admin_import_model"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x0000000fa53250 @tempfile=#Tempfile:C:/Users/DAVIDL~1/AppData/Local/Temp/RackMultipart20160304-6960-w8sf1v.csv, @original_filename="buses (1).csv", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name="active_admin_import_model[file]"; filename="buses (1).csv"\r\nContent-Type: application/octet-stream\r\n">}, "commit"=>"Import"}

may i see your paramters?

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

im using google chrome

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

Parameters: {"utf8"=>"✓", "authenticity_token"=>"08bDVAuC3ijCAtLlTGvTN6n+OsBciLsRKHfdVNkrAjfp7MWgYYMisF3V2Ka0YdN6dkqcXqutLyujY+wLRSrUrg==", "active_admin_import_model"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x007fb165c62898 @tempfile=#Tempfile:/var/folders/g8/1r7jmb011_x7c20kd45dfb1h0000gn/T/RackMultipart20160304-98171-vhb68h.csv, @original_filename="buses (1).csv", @content_type="text/csv", @headers="Content-Disposition: form-data; name="active_admin_import_model[file]"; filename="buses (1).csv"\r\nContent-Type: text/csv\r\n">}, "commit"=>"Import"}

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

aw i see it, content-type, Do i have to do something to fix this?

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow, this gem still doesn't detect mime type automatically, if this stops you from developing , just disable it and keep going by monkey-patching with your initializer

class ActiveAdminImport::Model
  def correct_content_type
     true
   end
end

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

one more thing I noticed is that your database timestamps column are not nullable,

To make import work use something like .

active_admin_import validate: true,
                      csv_options: {col_sep: ";" },
                      timestamps: true,
                      resource_class: BusImport ,  # we import data into another resource
                      # before_import: proc{ .delete_all },
                      after_import: proc{
                        Bus.transaction do
                          Bus.connection.execute("INSERT INTO buses (created_at, updated_at, name,btype,reg_no,body_no,plate_no,capacity) (SELECT created_at, updated_at, name,btype,reg_no,body_no,plate_no,capacity FROM bus_imports)")
                        end
                      },

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

wow thank you its working now.

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow , let me show how I would do this.

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024
after_import: proc{
                        Bus.transaction do
                          Bus.connection.execute("INSERT INTO buses (company_id, name,btype,reg_no,body_no,plate_no,capacity) (SELECT #{current_admin_user.company_id}, name,btype,reg_no,body_no,plate_no,capacity FROM bus_imports)")
                        end
                      },

is there any other way to do this? seems like that there is no current_admin_user

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024
  before_filter only: [:do_import] do
    Thread.current['import.bus.company_id'] = current_admin_user.company_id
  end
  active_admin_import validate: false,
                      timestamps: true,
                      template_object: ActiveAdminImport::Model.new(
                          hint: "file will be imported with such header format: 'Bus Name','Registration ID','Body Number','Plate Number','Capacity'",
                          csv_headers: ["name" ,"btype", "reg_no", "body_no", "plate_no", "capacity", "company_id"],
                          csv_options: { col_sep: ";", quote_char: '"' }),
                          before_batch_import: ->(importer) { importer.csv_lines.map{|line| line <<  Thread.current['import.bus.company_id'] }}

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow , did it help ?

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

wow , yes it works like a charm!

from active_admin_import.

Fivell avatar Fivell commented on July 30, 2024

@spurdow , good luck with your project

from active_admin_import.

spurdow avatar spurdow commented on July 30, 2024

@Fivell ah thanks , its not really my project im seriously trying hard to learn this framework, cause i love the syntax and how the framework works.

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.