# Can't find YAML file via code (though it exists in /app)

**URL:** <https://www.ruby-forum.com/t/cant-find-yaml-file-via-code-though-it-exists-in-app/167662>\
**Category:** Rails\
**Created:** [May 11, 2009, 9:08am UTC](https://www.ruby-forum.com/t/cant-find-yaml-file-via-code-though-it-exists-in-app/167662 "2009-05-11T09:08:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@ahad](https://www.ruby-forum.com/u/ahad)\
**Post date:** [May 11, 2009, 9:08am UTC](https://www.ruby-forum.com/t/cant-find-yaml-file-via-code-though-it-exists-in-app/167662/1 "2009-05-11T09:08:45Z")

</div>

Hey guys,

I’m trying to access a YAML file to set up some options in a select  
drop-down that was previously hard-coded.

I have the following in my controller:

require “yaml”  
require “pp”  
require “util”  
require “date”

# set the path

$LOAD\_PATH \<\< File.join(File.dirname( **FILE** ), ‘…/’)

require ‘rate’  
require ‘test/unit’  
require ‘yaml’

#require ‘rubygems’  
#require ‘ruby-debug/debugger’

YAML\_CONFIG\_FILE\_STR = “LawyersProfessionalLiability.yaml”  
YAML\_CONFIG\_FILE =  
File.join(File.expand\_path(File.dirname( **FILE** )),"…",YAML\_CONFIG\_FILE\_STR)

class LplShortFormAppsController \< ApplicationController

def initialize(filename = “LawyersProfessionalLiability.yaml”)  
# load all lookup tables  
@RateLookup = YAML::load(File.open(filename))

```
reset

```

end

def new  
# load all lookup tables  
@RateLookup = YAML::load(File.open(YAML\_CONFIG\_FILE))  
@deductibles = @RateLookup[“Deductible”]  
@desired\_limits = @RateLookup[“Liability Limits”]

```
@lpl_short_form_app = LPLShortFormApp.new

respond_to do |format|
  format.html # new.html.erb
  format.xml { render :xml => @lpl_short_form_app }
end

```

end  
…  
end

And the code in the view doesn’t matter yet because I keep receiving:

Errno::ENOENT in Lpl short form appsController#index

No such file or directory - LawyersProfessionalLiability.yaml

RAILS\_ROOT: /Users/brwn/work/demo  
Application Trace | Framework Trace | Full Trace

/Users/brwn/work/demo/app/controllers/lpl\_short\_form\_apps\_controller.rb:31:in  
`initialize' /Users/brwn/work/demo/app/controllers/lpl_short_form_apps_controller.rb:31:in`open’

I don’t know why. Where is the YAML file supposed to go? I’ve tried  
placing it in /app, /public, /views/, /views/lpl\_short\_form\_apps (the  
view where the YAML file is being called to load).

Can anyone assist?

Thanks,  
Ahad

---

<div class="post-metadata">

**Author:** ![ahad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@ahad](https://www.ruby-forum.com/u/ahad)\
**Post date:** [May 11, 2009, 10:34am UTC](https://www.ruby-forum.com/t/cant-find-yaml-file-via-code-though-it-exists-in-app/167662/2 "2009-05-11T10:34:47Z")

</div>

On May 11, 8:08 am, Ahad A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I don’t know why. Where is the YAML file supposed to go? I’ve tried  
> placing it in /app, /public, /views/, /views/lpl\_short\_form\_apps (the  
> view where the YAML file is being called to load).
> 
> Can anyone assist?

Rather than guessing where it is, have you tried printing out the  
value of YAML\_CONFIG\_FILE ?

Fred

---

<div class="post-metadata">

**Author:** ![ahad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@ahad](https://www.ruby-forum.com/u/ahad)\
**Post date:** [May 11, 2009, 6:09pm UTC](https://www.ruby-forum.com/t/cant-find-yaml-file-via-code-though-it-exists-in-app/167662/3 "2009-05-11T18:09:00Z")

</div>

Frederick C. wrote:

> On May 11, 8:08ï¿½am, Ahad A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> Rather than guessing where it is, have you tried printing out the  
> value of YAML\_CONFIG\_FILE ?
> 
> Fred

Actually, I tried and failed. I used puts YAML\_CONFIG\_FILE in the index  
action as well as in the initialize method, but the server output showed  
no information upon reaching the error. I thought to put it into the  
Request section by using params[“debug”] = YAML\_CONFIG\_FILE but that  
also had no effect, except to make an empty Request section show up. I  
thought, well, maybe the path isn’t being setup at all, except the error  
specifically states the LawyersProfessionalLiability.yaml file, without  
any path, so I know it’s getting set, I just don’t know to where or how  
to make it display where.

---

<div class="post-metadata">

**Author:** ![ahad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@ahad](https://www.ruby-forum.com/u/ahad)\
**Post date:** [May 11, 2009, 7:32pm UTC](https://www.ruby-forum.com/t/cant-find-yaml-file-via-code-though-it-exists-in-app/167662/4 "2009-05-11T19:32:26Z")

</div>

Ahad A. wrote:

> Frederick C. wrote:
> 
> > On May 11, 8:08ï¿½am, Ahad A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > wrote:
> > 
> > Rather than guessing where it is, have you tried printing out the  
> > value of YAML\_CONFIG\_FILE ?
> > 
> > Fred
> 
> Actually, I tried and failed. I used puts YAML\_CONFIG\_FILE in the index  
> action as well as in the initialize method, but the server output showed  
> no information upon reaching the error. I thought to put it into the  
> Request section by using params[“debug”] = YAML\_CONFIG\_FILE but that  
> also had no effect, except to make an empty Request section show up. I  
> thought, well, maybe the path isn’t being setup at all, except the error  
> specifically states the LawyersProfessionalLiability.yaml file, without  
> any path, so I know it’s getting set, I just don’t know to where or how  
> to make it display where.

Well, I tried puts on a lot of different areas and I was able to expose  
the problem. It came down to a simple parameter value not being passed  
in properly.

Thanks for the assistance.
