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

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:inopen’

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

On May 11, 8:08 am, Ahad A. [email protected]
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

Frederick C. wrote:

On May 11, 8:08�am, Ahad A. [email protected]
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.

Ahad A. wrote:

Frederick C. wrote:

On May 11, 8:08�am, Ahad A. [email protected]
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.