Hey Richard,
Sorry it's been so long, I seem to have dropped this thread.
1) My thought about attachment_fu is that it allows you to pull files
that are local to your "rails client" machine and bring them into the
rails application space. One way it's used is to enable rails users
to post their own images onto a site for sharing with the community.
There is a browser included that works much like the usual file
browser to aid with locating / selecting file for inclusion.
I'm not sure where your csv files live right now but if they're not
somewhere below RAILS_ROOT + "public" then you'll need to figure out
how to get them there. Attachment_fu can help here if the files are
user generated - field data and the like - that the user will upload
into the system.
2) The next thing is moving the data into your Model(s). I'm not sure
how comfortable you are with the quality of the data but I guarantee
that, no matter what approach you take, you'll need to constantly work
on data validation.
You'll probably do best if you start with one model for each file
type. That way you can use the model.rb file to validate, validate,
validate,... the data on it's way to the database.
3) Of course if it's your own data and you know it's always complete
and correct, you can take the migration file approach. It's a little
more raw than what is generally considered socially acceptable in the
RoR community. The real drawback is then specific database methods
leak in past the abstraction boundary. Notice the code for postgresql
differs from that for mysql - and we haven't even looked at sqlite3 or
db2 or ...
class CreateStateAbbrevs < ActiveRecord::Migration
def self.up
create_table :state_abbrevs do |t|
t.string :name
t.string :abbrev
end
csv_file = "#{RAILS_ROOT}/db/migrate/abbr_state.csv"
fields = '(name, abbrev)'
# PostgreSQL load from file...
execute "COPY state_abbrevs #{fields} FROM '#{csv_file}' WITH CSV"
# MySQL load from file...
# execute "LOAD DATA INFILE '#{csv_file}' INTO TABLE state_abbrevs
FIELDS " +
# "TERMINATED BY ',' OPTIONALLY ENCLOSED BY \"\"\"\" " +
# "LINES TERMINATED BY '\n' " + fields
end
def self.down
drop_table :state_abbrevs
end
end
So many buttons and so little time,
Rick