Kumar
Kumar

Reputation: 741

How to include a yml file in rails application?

I created a yml file called oauth.yml file. i want it to include it in the rails application. Where should i include it.

Upvotes: 2

Views: 3344

Answers (1)

Maurício Linhares
Maurício Linhares

Reputation: 40313

You should possibly include it under the config folder:

app/config/oauth.yml

Let's imagine your file is like this:

development:
  key: some_key
  secret: some_secret
test:
  key: some_key
  secret: some_secret

Now, somewhere in your rails app, possibly in an initializer file (under app/config/initializers) you'll load this file to a variable or class:

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

Upvotes: 6

Related Questions