简体   繁体   English

rails console - 运行一段代码

[英]rails console - run a block of code

I understand how to run a simple piece of code in rails console. 我理解如何在rails控制台中运行一段简单的代码。 say

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

How do I run a big piece of code (many lines) 我如何运行一大段代码(多行)

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

Just hit enter, as you'd expect: 按照你的预期点击输入:

$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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM