加载rails控制台并定义变量

时间:2013-06-08 18:11:09

标签: ruby-on-rails console

完成Michael Hartl的Ruby on Rails教程,并在2.3.3节中找到了障碍

“我们首先在命令行中使用rails console调用控制台,然后使用User.first从数据库中检索第一个用户(将结果放在变量first_user中):7”

任何帮助都会得到很多帮助

$ rails console
Loading development environment (Rails 3.2.13)
1.9.3-p429 :001 > >> first_user = User.first
SyntaxError: (irb):1: syntax error, unexpected tRSHFT
>> first_user = User.first
  ^
from /Users/MattPerloe/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /Users/MattPerloe/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /Users/MattPerloe/.rvm/gems/ruby-1.9.3-p429@rails3tutorial2ndEd/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

1 个答案:

答案 0 :(得分:2)

您无需在代码前添加>>

教程中的>>只是暗示在rails控制台中输入了以下命令。

以下就足够了:

rails console
first_user = User.first