Comments (43)
@spurdow, can you show your models BusImport and Bus
from active_admin_import.
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.
@spurdow , what about BusImport table ?
from active_admin_import.
@Fivell its just the same but without relationship only necessary fields for importing...
from active_admin_import.
@Fivell anyway, is there any way i could log the debug?
from active_admin_import.
@spurdow , application development.log or production.log depends on your env . Here
from active_admin_import.
btw, did you try validate: false
?
from active_admin_import.
yeah tried both false and true... I dont fully understand what it really validates.
from active_admin_import.
is my csv file wrong? or is there some options im missing?
from active_admin_import.
@spurdow , show me your development logs for this request.
from active_admin_import.
@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.
@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.
still the same :'(
from active_admin_import.
ill push my new commit today, i hope you will have the time to look it up.
from active_admin_import.
@Fivell how do I show the logs only for active admin import?. I dont quiet get it.
from active_admin_import.
@spurdow , launch your app in development mode, make an import and capture new lines from development.log
from active_admin_import.
oh so its already default to log in development sorry, My bad. Okay ill post anything I deem wrong.
from active_admin_import.
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.
@spurdow , send "buses (1).csv" file to my email
from active_admin_import.
Ive sent u an email
from active_admin_import.
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.
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.
@spurdow , I cloned your application and uploaded your file
from active_admin_import.
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.
from active_admin_import.
aww how did you get it to error message like that?, I always get Invalid Csv
from active_admin_import.
Ive updated it , its wrong it should be reg_no
from active_admin_import.
I always get this error. What sdk are you using?
from active_admin_import.
@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.
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.
im using google chrome
from active_admin_import.
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.
aw i see it, content-type, Do i have to do something to fix this?
from active_admin_import.
@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.
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.
wow thank you its working now.
from active_admin_import.
@spurdow , let me show how I would do this.
from active_admin_import.
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.
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.
@spurdow , did it help ?
from active_admin_import.
wow , yes it works like a charm!
from active_admin_import.
@spurdow , good luck with your project
from active_admin_import.
@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)
- Why version lock? HOT 3
- Getting SQL syntax error, as the values in the insert statement is having extra comma at the end. Also 'created_at' value is coming as null. HOT 3
- Add roles after importing users HOT 4
- Errors on the base of an object break active_admin_import HOT 1
- Wrong count in notification after successful import HOT 2
- on the fly by association - not working for a particular column
- need possibility to wrap whole process inside transaction HOT 1
- Proposal: live processing feedback using rails 5 action cables. HOT 1
- Handle a specific error on import HOT 3
- Creating associations without foreign keys
- Deprecation warnings in log
- Send to importer form additional params
- Calling batch_slice_columns multiple times results in unexpected behavior
- Ability to update or create based on id column being present
- Ability to import serialized hash HOT 1
- Ruby 3.0 Support
- ActiveModel::Errors#keys is deprecated and will be removed in Rails 6.2. HOT 2
- Proposal: Array conversion
- Release version 5? HOT 1
- Error if csv file consists empty columns
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from active_admin_import.