rails console - 运行一段代码

时间:2013-06-01 18:05:58

标签: ruby-on-rails ruby ruby-on-rails-3

我理解如何在rails控制台中运行一段简单的代码。说

 Swimming::Student.create(:name="Jerry")

如何运行大量代码(多行)

 Swimming::Student.all.each{ |student|
     student.attended = flase
     student.save
 }

1 个答案:

答案 0 :(得分:23)

按照你的预期点击输入:

$rails c
Loading development environment (Rails 3.2.13)
2.0.0p0 :001 > Student.all.each do |student| #enter
2.0.0p0 :002 >     puts student #enter
2.0.0p0 :003?> end #enter
# here comes the output