带有Rails的实用敏捷Web开发:如何运行此代码?

时间:2011-11-05 16:38:34

标签: ruby-on-rails-3

我正在阅读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

Transactions file example

1 个答案:

答案 0 :(得分:0)

如果需要,请在一行中输入所有内容:

Account.transaction do; paul.deposit(10); peter.withdraw(10); end

;用于在一行中分隔多个语句。

但是IRB应该允许你输入多行。完成上述操作后也要尝试。