# Environment.rb uninitialized constant when starting console

**URL:** <https://www.ruby-forum.com/t/environment-rb-uninitialized-constant-when-starting-console/134863>\
**Category:** Rails\
**Created:** [April 15, 2008, 7:15pm UTC](https://www.ruby-forum.com/t/environment-rb-uninitialized-constant-when-starting-console/134863 "2008-04-15T19:15:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yetanothergeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/8e8cbc/32.png) [@yetanothergeek](https://www.ruby-forum.com/u/yetanothergeek)\
**Post date:** [April 15, 2008, 7:15pm UTC](https://www.ruby-forum.com/t/environment-rb-uninitialized-constant-when-starting-console/134863/1 "2008-04-15T19:15:03Z")

</div>

I have the following code in environment.rb:

require File.join(File.dirname( **FILE** ), ‘boot’)

raw\_config = File.read(RAILS\_ROOT + “/config/config.yml”)  
APP\_CONFIG = YAML.load(raw\_config)[RAILS\_ENV]

This works fine when running the server, but if I try and start a  
console I get:

Loading development environment.  
./script/…/config/…/config/environment.rb:15:NameError:  
uninitialized constant YAML

Can anyone help me out? Thanks.

Chris

---

<div class="post-metadata">

**Author:** ![yetanothergeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/8e8cbc/32.png) [@yetanothergeek](https://www.ruby-forum.com/u/yetanothergeek)\
**Post date:** [April 15, 2008, 7:37pm UTC](https://www.ruby-forum.com/t/environment-rb-uninitialized-constant-when-starting-console/134863/2 "2008-04-15T19:37:29Z")

</div>

On 15 Apr 2008, at 18:10, Chris S wrote:

> Loading development environment.  
> ./script/…/config/…/config/environment.rb:15:NameError:  
> uninitialized constant YAML
> 
> Can anyone help me out? Thanks.

You probably need a require ‘yaml’ before you use yaml. I’m guess that  
when you run the server, the server itself loads yaml for its own  
purposes before doing the railsy stuff and so you get lucky.

Fred

---

<div class="post-metadata">

**Author:** ![yetanothergeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/8e8cbc/32.png) [@yetanothergeek](https://www.ruby-forum.com/u/yetanothergeek)\
**Post date:** [April 15, 2008, 7:52pm UTC](https://www.ruby-forum.com/t/environment-rb-uninitialized-constant-when-starting-console/134863/3 "2008-04-15T19:52:16Z")

</div>

That did the trick, thanks Fred.

On Apr 15, 12:36 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
