Import excel / csv files

Hey, What way is the best to do imports of CSV files?

If you mean CSV to DB records, you should use fixtures.

On terminal window. rake db:fixtures:load FIXTURES=table_name RAILS_ENV=development

Change 'table_name' and RAILS_ENV=~ as you like. This will import CSV as DB records.

Thank's Masuda, but what im looking for is a solution where the user can upload a CSV file an update the DB records that way.

Goro Kuroita wrote:

If you mean CSV to DB records, you should use fixtures.

On terminal window. rake db:fixtures:load FIXTURES=table_name RAILS_ENV=development

Change 'table_name' and RAILS_ENV=~ as you like. This will import CSV as DB records.

Poppycock. Fixtures are so broken that they're worth avoiding completely (I wish they'd be removed from Rails). For prepopulating the DB, use the DB's native CSV import or something like seed_fu. For dynamic CSV import in the application, fastercsv might be useful.

Best,

Why do you say that fixtures are broken?

Milan Dobrota wrote:

Why do you say that fixtures are broken?

The short answer is that they're unsuited to their intended purpose (populating the test DB). They're better than nothing, but are an inferior alternative to other solutions now available. I'll get into the long answer if you really want, or just search the list archives.

Best,