I picked up on the buzz about RoR and wanted to see what the fuss is
about. So far i am very impressed but have hit a bit of a wall with a
little play app i am writting.
I want to iterate through a CSV file of my bank transactions and see
just how much money i spend on beer and pies every month.
I have successfully setup a database with a single table called
transactions and setup a skeleton and entered a few records using the
basic CRUD functions. I have also installed FasterCSV and successfully
listed the contents of the csv file. I thought it would be a simple step
to loop through the file and insert the values in to the db. In addition
to the generated admin_controller.rb file containing list, update etc i
@csv_trans_action = FasterCSV.read(“c:/nugget/statement.csv”)
@csv_trans_actions = FasterCSV.read(“c:/nugget/statement.csv”)
for trans_action in @trans_actions for csv_trans_action in @csv_trans_actions trans_action.trans_date_at = csv_trans_action trans_action.description = csv_trans_action trans_action.amount = csv_trans_action trans_action.save end
What is funny is that it seems to insert the first row and then throw an
error about a array value being nil (Sorry don’t have the exact message
to hand). This is a bit of a stab in the dark regarding how to do this
so if anyone has any comments i’d be very grateful.
I am also wondering how i would return what happended back to