我正在阅读Pragmatic rails应用程序书并在书中写着“运行此代码”时遇到pb。
我的问题是如何运行Account.creation.do
块代码?怎么运行这个?控制台只接受一行。链接到下面的文件。
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
答案 0 :(得分:0)
如果需要,请在一行中输入所有内容:
Account.transaction do; paul.deposit(10); peter.withdraw(10); end
;
用于在一行中分隔多个语句。
但是IRB应该允许你输入多行。完成上述操作后也要尝试。