11

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
 }
1
  • just enter it like that. The whole block is executed, once it's complete Commented Jun 1, 2013 at 18:09

1 Answer 1

29

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
Sign up to request clarification or add additional context in comments.

1 Comment

Also, semicolon: `Product.all.each{|p| puts p; p.shown = true}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.