我创建了一个名为 oauth.yml 文件的 yml 文件。我希望它将它包含在 Rails 应用程序中。我应该把它包含在哪里。
最佳答案
您应该将其包含在配置文件夹下:
app/config/oauth.yml
假设您的文件是这样的:
development:
key: some_key
secret: some_secret
test:
key: some_key
secret: some_secret
现在,在 Rails 应用程序中的某个位置,可能在初始化程序文件中(在 app/config/initializers 下),您可以将此文件加载到变量或类中:
all_oauth_config = YAML.load_file( File.join( Rails.root, 'app', 'config', 'oauth.yml' ) )
current_oauth_config = all_oauth_config[Rails.env]
#now do something with this current_oauth_config variable
关于ruby-on-rails - 如何在rails应用程序中包含yml文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6867234/