Ahad Amdani
2009-May-11 07:08 UTC
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: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 -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-May-11 08:33 UTC
Re: Can''t find YAML file via code (though it exists in /app)
On May 11, 8:08 am, Ahad Amdani <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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> > Thanks, > Ahad > -- > Posted viahttp://www.ruby-forum.com/.
Ahad Amdani
2009-May-11 16:09 UTC
Re: Can''t find YAML file via code (though it exists in /app)
Frederick Cheung wrote:> On May 11, 8:08�am, Ahad Amdani <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > Rather than guessing where it is, have you tried printing out the > value of YAML_CONFIG_FILE ? > > FredActually, 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. -- Posted via http://www.ruby-forum.com/.
Ahad Amdani
2009-May-11 17:32 UTC
Re: Can''t find YAML file via code (though it exists in /app)
Ahad Amdani wrote:> Frederick Cheung wrote: >> On May 11, 8:08�am, Ahad Amdani <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt> >> 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. -- Posted via http://www.ruby-forum.com/.