Besi
Besi

Reputation: 22939

Rails console stops to output any text

I have a rails application and I execute some queries in the bin/rails console.

Now when I was doing a query to output some data suddenly the output stopped being displayed.

I can then assign a variable a given value and entering the variable does not output the value I just assigned:

irb(main):001:0> Card.all.each do {|c| print("#{c.full_name}: #{c.id}/#{c.first_name}-#{c._lastname}")  }
irb(main):004:2> x = _
irb(main):005:2> x
irb(main):006:2> x = 3 
irb(main):007:2> x # I would assume to see the value '3'
irb(main):009:3> print("hello") # I would assume to see "hello" on the screen
irb(main):010:3> 

Upvotes: 1

Views: 283

Answers (1)

tadman
tadman

Reputation: 211610

This usually happens because of dangling syntax. In your case you're using both do ... end and { ... }, notably omitting the end.

The IRB parser will continue to take input until you put in an end, and only then will it run and/or emit an error.

The fix is to scratch out the do.

You want either:

Card.all.each do |c|
  ...
end

Or the inline style:

Card.all.each { |c| ... }

Upvotes: 4

Related Questions