Forum: Ruby on Rails Can't find YAML file via code (though it exists in /app)

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.
36d14958934ec98b2f84669bb60d78d3?d=identicon&s=25 Ahad Amdani (ahad)
on 2009-05-11 09:08
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-11 10:34
(Received via mailing list)
On May 11, 8:08 am, Ahad Amdani <rails-mailing-l...@andreas-s.net>
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
36d14958934ec98b2f84669bb60d78d3?d=identicon&s=25 Ahad Amdani (ahad)
on 2009-05-11 18:09
Frederick Cheung wrote:
> On May 11, 8:08�am, Ahad Amdani <rails-mailing-l...@andreas-s.net>
> 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.
36d14958934ec98b2f84669bb60d78d3?d=identicon&s=25 Ahad Amdani (ahad)
on 2009-05-11 19:32
Ahad Amdani wrote:
> Frederick Cheung wrote:
>> On May 11, 8:08�am, Ahad Amdani <rails-mailing-l...@andreas-s.net>
>> 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.
This topic is locked and can not be replied to.