Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails console - run a block of code

I understand how to run a simple piece of code in rails console. 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
 }
like image 743
wwli Avatar asked Jun 01 '13 18:06

wwli


1 Answers

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
like image 82
tsm Avatar answered Oct 12 '22 21:10

tsm