# Rails console doesn't run scripts, why?

**URL:** <https://www.ruby-forum.com/t/rails-console-doesnt-run-scripts-why/113730>\
**Category:** Rails\
**Created:** [September 4, 2007, 12:47pm UTC](https://www.ruby-forum.com/t/rails-console-doesnt-run-scripts-why/113730 "2007-09-04T12:47:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![snaggy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@snaggy](https://www.ruby-forum.com/u/snaggy)\
**Post date:** [September 4, 2007, 12:47pm UTC](https://www.ruby-forum.com/t/rails-console-doesnt-run-scripts-why/113730/1 "2007-09-04T12:47:41Z")

</div>

I’m trying to generate a controller (but I have this problem with  
every script):

Loading development environment.

> > ./script/generate controller Ciao  
> > SyntaxError: compile error  
> > (irb):1: syntax error, unexpected ‘.’  
> > ./script/generate controller Ciao  
> > ^  
> > (irb):1: syntax error, unexpected tIDENTIFIER, expecting kDO or ‘{’ or  
> > ‘(’  
> > ./script/generate controller Ciao  
> > ^  
> > from (irb):1

How can I solve it?  
thanks

---

<div class="post-metadata">

**Author:** ![snaggy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@snaggy](https://www.ruby-forum.com/u/snaggy)\
**Post date:** [September 4, 2007, 1:39pm UTC](https://www.ruby-forum.com/t/rails-console-doesnt-run-scripts-why/113730/2 "2007-09-04T13:39:33Z")

</div>

Snaggy wrote:

> I’m trying to generate a controller (but I have this problem with  
> every script):
> 
> Loading development environment.
> 
> > > ./script/generate controller Ciao

don’t do that in a rails console but directly on the shell

ruby script/generate controller Ciao

the rails console is to directly type ruby code, not to start scripts.

---

<div class="post-metadata">

**Author:** ![snaggy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@snaggy](https://www.ruby-forum.com/u/snaggy)\
**Post date:** [September 4, 2007, 1:59pm UTC](https://www.ruby-forum.com/t/rails-console-doesnt-run-scripts-why/113730/3 "2007-09-04T13:59:54Z")

</div>

Thanks so much. Since I don’t understand much of ruby and rails, could  
you point me to some interesting tutorials on how the console works?

And can you tell me the difference between ruby and rails? I mean,  
when i start the console through script/console is that ruby or rails?  
and how can I call IRB without rails?  
bye  
thanks

---

<div class="post-metadata">

**Author:** ![snaggy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@snaggy](https://www.ruby-forum.com/u/snaggy)\
**Post date:** [September 4, 2007, 3:17pm UTC](https://www.ruby-forum.com/t/rails-console-doesnt-run-scripts-why/113730/4 "2007-09-04T15:17:15Z")

</div>

Console is an interactive ruby (irb) session in which the rails  
environment has already been loaded. irb (the normal interactive ruby)  
is simply started with the irb command.

> > ./script/generate controller Ciao

Console and irb are used to allow you to run ruby code interactively  
(hence the name) so in the console this isn’t a system call to the  
generate script, it’s just invalid ruby syntax.

For the record, you can use `` (backticks) or system() to enclose a  
shell command that is executed with the STDOUT value given as the  
return, ie:

> > `./script/generate controller Ciao`

But you wouldn’t actually do this in practice. You would simply  
execute ./script/generate controller Ciao in your shell as neongrau\_  
mentioned.

You can learn about ruby and irb in \_why’s poignant guide and the ruby  
pickaxe, both available for free online. You can learn about console  
in the README in your rails app, in various tutorials on the internet,  
and in the Agile Web D. With Rails book by the Pragmatic  
Programmers, which I recommend.

Rein  
[http://reinh.com](http://reinh.com)
