面对问题'读':没有这样的文件或目录@> rails中的rb_sysopen

时间:2016-10-25 08:07:59

标签: ruby-on-rails ruby-on-rails-4 basic-authentication

您好我已经在我的代码中包含了代码 配置/ app_config.yml

development:
  name: mytest
  password: secret
production:
  name: test
  password: Patest

配置/ application.rb中

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
APP_CONFIG = YAML.load_file("#{::Rails.root}/config/app_config.yml")[::Rails.env]

应用程序/控制器/ application_controller.rb

http_basic_authenticate_with :name => APP_CONFIG[:name], :password => APP_CONFIG[:password]

现在当我运行rails服务器时,它会给我以下错误::

  

config / application.rb:8:in read': No such file or directory @ rb_sysopen - /config/app_config.yml (Errno::ENOENT) from /Users/rails_app/config/application.rb:8:in'

请指导我在代码中缺少的如何解决此问题。

1 个答案:

答案 0 :(得分:0)

你应该添加

APP_CONFIG = YAML.load_file("#{::Rails.root}/config/app_config.yml")[::Rails.env]

Application课程内。

module Something
  class Application < Rails::Application
    # something

    APP_CONFIG = YAML.load_file("#{::Rails.root}/config/app_config.yml")[::Rails.env]
  end
end