Importer class never found
Closed this issue · 5 comments
I couldn't get this to work in a reasonable amount of time, so I was wondering where you typically place your importer files in a Rails application.
I tried putting my ImportItemsCSV
in the models
directory but even then I end up getting NoMethodError - undefined method
new' for nil:NilClass:` when I try to instantiate it in a controller.
You should be doing something wrong. Check again the file name and file syntax,
Read the manuals:
class ImportUserCSV
include CSVImporter
model User # an active record like model
column :email, to: ->(email) { email.downcase }, required: true
column :first_name, as: [ /first.?name/i, /pr(é|e)nom/i ]
column :last_name, as: [ /last.?name/i, "nom" ]
column :published, to: ->(published, user) { user.published_at = published ? Time.now : nil }
identifier :email # will update_or_create via :email
when_invalid :skip # or :abort
end
Ensure you have specified a model class, like: model User
@ACPK Are you running into a similar issue? If you use Rails, any class defined in a file (with matching name) will be loaded from any directory under app
.
An importer called "ImportUserCSV" can be defined in app/models/import_user_csv.rb
(or app/importers/import_user_csv.rb
....)
All the details are here: http://guides.rubyonrails.org/autoloading_and_reloading_constants.html