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.

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.

Can you exapnd on this idea, I needed to bring in a whole load of
records to my app from a CSV and wrote a custom method (with fasterCSV)
to read them in. Am now wondering if fixtures would have been a better
way to go and maybe I should be using them in future as I import more
data to my app?

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,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Milan D. 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,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Why do you say that fixtures are broken?

On Sep 22, 4:22 pm, Marnen Laibow-Koser <rails-mailing-l…@andreas-

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs