Why can't Rails find this custom .yml file?
In applications.rb I added this:
SOME_CONFIG = = YAML.load_file(File.expand_path('../some_config.yml', __FILE__))
I placed the file in:
/some/folder/myapp/config/some_config.yml
Then when I run 'rails server' I开发者_运维问答 get an error:
.. in 'initialize' : no such file or directory /some/folder/myapp/config/some_config.yml (Errno::ENDENT) .... 'open' .... 'load_file' ....
Is this a permissions issue?
I don't believe this to be a permissions issue.
1) Double check your spelling to make sure there are no typos.
2) Try reading another file, and see if it works.
3) Try: YAML.load_file(File.join(Rails.root, 'config', 'some_config.yml'))
(Your error message shows that the issue is not in expanding the filename, but you never know).
4) Can you access it from the console?
my_data = HashWithIndifferentAccess.new( YAML.load(File.read(File.expand_path('../../some_file.yml', __FILE__))) )
now due to HashWithIndifferentAccess, you can get data in any of the given below syntax
my_data[:some_key] or my_data['some_key']
精彩评论