pcreux / csv-importer

CSV Import for humans on Ruby / Ruby on Rails
MIT License
590 stars 67 forks source link

update the readme #94

Closed Tresor11 closed 4 years ago

Tresor11 commented 4 years ago

I'm using the csv-importer with 'rails', '~> 6.0.3' and ruby '2.7.1' while creating an importer I ran into the following error. <class:MyImporter>': uninitialized constant MyImporter::CSVImporter (NameError) I had to require the csv-importer before I could include it in my importer class. I thought it might be useful to mention that so In this PR I updated the usage section of the README

pcreux commented 4 years ago

Thank you for reporting that.

You shouldn't have to require csv-importer. Having the gem listed in the Gemfile should be sufficient.

I'm wondering if that could be related to Ruby 2.7 and / or Rails Zeitwerk?

Tresor11 commented 4 years ago

Thank you for reporting that.

You shouldn't have to require csv-importer. Having the gem listed in the Gemfile should be sufficient.

I'm wondering if that could be related to Ruby 2.7 and / or Rails Zeitwerk?

Thank you for looking at this PR, as you mentioned the problem is likely to be related to those two. maybe we could mention in the readme that users with Ruby 2.7 might need to require csv-importer first

Edit

after a little troubleshooting, I realized that giving the class the same name as the file solves the issue.

ex: My file name was cars_importer.rb and my class name was class CarImporter by changing it to class CarsImporter the the issue was solved.

I'd like to know if that worth mentioning in the readme, if not this can be closed thanks

pcreux commented 4 years ago

Oh, I just noticed your edit. Indeed, rails autoloading requires the class and file name to match. Thank you for the update!