Forum: Ruby on Rails Apache/fastcgi setup can't find custom config/*.yml file!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Wes G. (Guest)
on 2006-04-13 19:53
All,

Apache 2/FastCGI on Linux

My fastcgi config. file is set up to run the "test" RAILS_ENV.

When I go to access a view associated with a particular controller, I
keep getting a ENOENT (file not found) error on a custom config. file
that I am attempting to load.

What I can't figure out is why it can't find the file.

Here's the code that loads it in my controller:

require 'yaml'

class ESimplyController < ApplicationController
  @@config = ""
  @@config = YAML.load_file("config/eSimplyConf.yml")

This setup works fine in my development environment.

When this code gets called, I get the following error in my test.log
file:

Errno::ENOENT (No such file or directory - config/eSimplyConf.yml):
    /usr/lib/ruby/1.8/yaml.rb:143:in `initialize'
    /usr/lib/ruby/1.8/yaml.rb:143:in `load_file'
    /app/controllers/e_simply_controller.rb:5
    /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require'
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenc
ies.rb:147:in `require'
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenc
ies.rb:65:in `require_or_load'
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenc
ies.rb:30:in `depend_on'
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenc
ies.rb:85:in `require_dependency'
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenc
ies.rb:98:in `const_missing'
    /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenc
ies.rb:131:in `const_missing'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/routing.
rb:237:in `traverse_to_controller'
    generated/routing/recognition.rb:30:in `eval'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/routing.
rb:237:in `traverse_to_controller'
    generated/routing/recognition.rb:30:in `recognize_path'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/routing.
rb:477:in `recognize!'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:in
`dispatch'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/fcgi_handler.rb:150:in
`process_
request'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/fcgi_handler.rb:54:in
`process!'
    /usr/lib/ruby/1.8/fcgi.rb:600:in `each_cgi'
    /usr/lib/ruby/1.8/fcgi.rb:117:in `session'
    /usr/lib/ruby/1.8/fcgi.rb:104:in `each_request'
    /usr/lib/ruby/1.8/fcgi.rb:36:in `each'
    /usr/lib/ruby/1.8/fcgi.rb:597:in `each_cgi'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/fcgi_handler.rb:53:in
`process!'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/fcgi_handler.rb:23:in
`process!'
    /var/www/html/eSimplyTest/public/dispatch.fcgi:26


Rendering
/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/te
mplates/rescues/layout.rhtml (500 Internal Error)

=========== END OF ERROR =======================

I'm under the impression that the relative path to my config file is OK
and that it will just be interpreted relative to RAILS_ROOT (which to
the best of my knowledge, is correct)?  Is that not true for some
reason?

Thanks,
Wes
Wes G. (Guest)
on 2006-04-13 20:17
What I really can't figure out is why it can find the database.yml file
but not my custom one.

Is there something special about the way that yaml.rb looks for files?

Some env. var. that I need to set?

Wes
Ezra Z. (Guest)
on 2006-04-14 01:35
(Received via mailing list)
On Apr 13, 2006, at 9:17 AM, Wes G. wrote:

> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails

Wes-

	When you try to load files from the filesystem in a rails app, never
use relative paths or you will get errors just like you are seeing.
Change this line:

@@config = YAML.load_file("config/eSimplyConf.yml")

To this:

@@config = YAML.load_file("#{RAILS_ROOT}/config/eSimplyConf.yml")

And you will be good to go.

Cheers-
-Ezra
Wes G. (Guest)
on 2006-04-14 01:58
Ezra,

Thanks!  That was exactly my problem - that I wasn't using "absolute"
paths.

Just growing pains into big-boy deployment.

When's your book coming out and what will it be?

Wes

Ezra Z. wrote:
> On Apr 13, 2006, at 9:17 AM, Wes G. wrote:
>
>> --
>> Posted via http://www.ruby-forum.com/.
>> _______________________________________________
>> Rails mailing list
>> removed_email_address@domain.invalid
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>
> Wes-
>
> 	When you try to load files from the filesystem in a rails app, never
> use relative paths or you will get errors just like you are seeing.
> Change this line:
>
> @@config = YAML.load_file("config/eSimplyConf.yml")
>
> To this:
>
> @@config = YAML.load_file("#{RAILS_ROOT}/config/eSimplyConf.yml")
>
> And you will be good to go.
>
> Cheers-
> -Ezra
Ezra Z. (Guest)
on 2006-04-14 03:41
(Received via mailing list)
Wes-

	THe book is called Rails Deployment. SO it will cover running your
own VPS or dedicated server for rails as well as shared hosting and
clusters. It also has many practical development techniques and
advanced active record tips and well as a TDD and BDD chapter. I am
pushing hard to get the beta book out before RailsCOnf in June.

Cheers-
-Ezra
This topic is locked and can not be replied to.