Strange Rails Console Behavior

When I run a multiline statement in the Rails 3.0.1 console, pressing Enter does not actually run the statement. Instead, it jumps to a new console line, and the cursor has a tab to the right. Then I have to run the base line (e.g. p "hey"), and then the multi-line statement will be executed.

ruby-1.9.2-p0 > images = Image.all;images.each do |im|; if im.imagestore_width.blank?;im.save;end;
ruby-1.9.2-p0 >     p "hey"

I have been doing this for so long and it worked fine. But now I have a problem in the console, and this could be related. When I ran the above code, instead of working as usual, it just switched to a new console line with? added

ruby-1.9.2-p0 > images = Image.all;images.each do |im|; if im.imagestore_width.blank?;im.save;end;
ruby-1.9.2-p0 >     p "hey"
ruby-1.9.2-p0 ?>

When this happens, I cannot exit the console

ruby-1.9.2-p0 ?>  exit
ruby-1.9.2-p0 ?>  ^C

Are these issues related? How can I fix them?

+3
source share
2 answers

In line:

images = Image.all;images.each do |im|; if im.imagestore_width.blank?;im.save;end;

end, if, end, do each.

, .

Try:

images = Image.all;images.each do |im|; if im.imagestore_width.blank?;im.save;end;end

: . irb console , ,

irb(main):010:0> (3 *
irb(main):011:1* (2 + 1)
irb(main):012:1> )
=> 9
+4

, irb/console, ruby ​​ :

images = Image.all.each { |im| im.save if im.imagestore_width.blank? }

, {}, / ruby.

+1

Source: https://habr.com/ru/post/1786359/


All Articles