# Ruby script / console and models

**URL:** <https://www.ruby-forum.com/t/ruby-script-console-and-models/64801>\
**Category:** Rails\
**Created:** [August 15, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/ruby-script-console-and-models/64801 "2006-08-15T14:19:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 15, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/ruby-script-console-and-models/64801/1 "2006-08-15T14:19:10Z")

</div>

Is it possible to access models when your in the console ? It seems  
like that is not possible and I need to create the classes within the  
console. Am I doing something wrong ?

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 15, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/ruby-script-console-and-models/64801/2 "2006-08-15T14:19:10Z")

</div>

After posting this question I went ahead and did some googling so I  
found the parameters  
NAME and DESCRIPTION but found I’m getting these errors:

C:\InstantRails\rails\_apps\r4rmusic\>ruby script/console NAME  
Loading NAME environment.  
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.1.4/lib/initializer.rb:168:in  
`read’:Errno::ENOENT: No such file or  
directory - ./script/…/config/…/config/…/config/environments/NAME.rb

> >

C:\InstantRails\rails\_apps\r4rmusic\>ruby script/console DESCRIPTION  
Loading DESCRIPTION environment.  
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.1.4/lib/initializer.rb:168:in  
`read’:Errno::ENOENT: No such file or  
directory -  
./script/…/config/…/config/…/config/environments/DESCRIPTION.rb

So now that I think I know how to access the models and controllers  
from console, I seem to have a problem.  
Any ideas ?

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 15, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/ruby-script-console-and-models/64801/3 "2006-08-15T14:19:17Z")

</div>

On Aug 13, 2006, at 11:35 AM, Dark A. wrote:

> Is it possible to access models when your in the console ? It seems  
> like that is not possible and I need to create the classes within the  
> console. Am I doing something wrong ?
> 
> Stuart
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

```
Yes its possible. Actually thats pretty much the main point of

```

script/console. In order to tell it what env you want to run in try  
this:

$ script/console production

OR

$ script/console test

OR

$ script/console # this one will default to development env.

Then your models are just available in the console. Am I missing  
something about your problem?

-Ezra

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 15, 2006, 2:20pm UTC](https://www.ruby-forum.com/t/ruby-script-console-and-models/64801/4 "2006-08-15T14:20:36Z")

</div>

On Mon, 2006-08-14 at 07:54 -0600, Dark A. wrote:

> class User  
> end  
> now i can add a new user . However the same goes for any methods that  
> maybe defined within that model. Those also seem to need to be  
> recreated in the console.
> 
> My assumption was that when entering console all controllers and  
> models (including the methods withing) would be immediately available.  
> So what am I doing wrong ?

* * *

$ script/console

> > require “app/models/user.rb”

Craig

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [August 15, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/ruby-script-console-and-models/64801/5 "2006-08-15T14:19:55Z")

</div>

My problem is that it seems within console the models are not  
available immediately.  
As an example I have a model name user.rb. Table is set up  
accordingly. I’m connected to the database.  
I open console and do:

abe = User.new

This won’t work as User is not recognized.  
I’m forced to define the class again in the console.  
class User  
end  
now i can add a new user . However the same goes for any methods that  
maybe defined within that model. Those also seem to need to be  
recreated in the console.

My assumption was that when entering console all controllers and  
models (including the methods withing) would be immediately available.  
So what am I doing wrong ?

Stuart
