2013-06-01 21 views
7

我明白如何在rails控制檯中運行一段簡單的代碼。說rails console - 運行一段代碼

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

如何運行一個大的一段代碼(多線)

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

回答

16

只需點擊進入,你會期望:

$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 
+2

另外,分號:'Product.all.each {| P |把p; p.shown = true} – Narfanator

1

只需輸入它這樣。整個塊被執行,一旦完成