column col, :float
else
t.column col, :string
end
end
end
end
end
This code uses the column definitions from the first line of the CSV file to create the
table column definitions and determine the order of the fields. This way, you won??™t need
to rely on fixed CSV file layouts or fixed table definitions.
Specifically, the ActiveRecord::Schema.define method is used to create a schema definition.
The program has a hard-coded list of date, float, and string fields, but they aren??™t
exhaustive, since PayPal can change the format at any time. In a production environment,
you would likely use a fixed schema. However, this approach is very flexible and
will work through simple format changes. In fact, the loading portion contains very little
code that is specific to the PayPal format, so you could fairly easily use it on another CSV
file; the code would create a simple schema to represent it.
Next, the remaining lines of the CSV file contain data, so each line following the first
should be entered into the database, assuming it hasn??™t already been entered:
else
if PaypalTransaction.
Pages:
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211