I’m reading the Pragmatic rails app book and running into a pb when the books says ‘Run this code’.
My problem is how to run the Account.creation.do block code? How to run this?. The console only accepts one line. Link to the file below.
So, now let’s write the code to transfer money between two accounts. It’s pretty straightforward:
peter = Account.create(:balance => 100, :number => "12345")
paul = Account.create(:balance => 200, :number => "54321")
Account.transaction do
paul.deposit(10)
peter.withdraw(10)
end
We check the database, and, sure enough, the money got transferred:
depot> sqlite3 -line db/development.sqlite3 "select * from accounts"
id = 1
number = 12345
balance = 90
id = 2
number = 54321
balance = 210
Type it all in one line if you want:
The
;is to be used to separate multiple statements on one line.But IRB should allow you to type multiple lines as well. Try that too after you have done the above.