Matt
Matt

Reputation: 1

Rails terminal stops processing Ruby code on Cloud 9 IDE (Ruby on Rails Tutorial)

I tried searching for this but couldn't come up with anything. I am following Michael Hartl's Ruby on Rails tutorial and am in chapter 4 trying to write methods in the Cloud 9 IDE terminal, but the rails console stops responding after one command, or doesn't work at all, as shown below. Any advice would be much appreciated.

$ rails console
Running via Spring preloader in process 31021
Loading development environment (Rails 5.0.1)
>> def random_subdomain {puts ('a'..'z').to_a.shuffle[0..7]}
>> a =1 
>> 
?> exit
>> ^C
>> 
?> ^C
>> ^C
>> 

Upvotes: 0

Views: 74

Answers (2)

ludolf
ludolf

Reputation: 11

You're missing an end statement from your function definition. So as far as the console knows, everything you typed after you hit the return key (a = 1, exit, Ctrl-C) is still part of the function definition. So it isn't that the console has stopped responding after one command; it is instead waiting for the matching end statement to your def.

Upvotes: 0

Sonu Singh
Sonu Singh

Reputation: 354

Remove the { and } and write this way

def random_subdomain 
 puts  ('a'..'z').to_a.shuffle[0..7]
end

and then paste this method in rails console then call this method like this

$ random_subdomain

then you should get expected output.

Upvotes: 0

Related Questions