Home > OS >  using existing variable in defined in secret.yml file in ruby
using existing variable in defined in secret.yml file in ruby

Time:07-22

I wanted to use already defined variable in ruby file. Below is my snippet from secret.yml file. However when I am accessing those variables in code, i am getting unexpected token at '

Could you please suggest how we can access these variable inside same file.

  GOOGLE_TYPE: "somevalues"
  GOOGLE_PROJECT: 'somevalues'
  GOOGLE_PRIVATE_KEY_ID: 'somevalues'
  GOOGLE_PRIVATE_KEY: "somevalues"
  GOOGLE_CLIENT_ID: 'somevalues'
  GOOGLE_CLIENT_EMAIL: 'somevalues'
  google_cloud_storage_credential_content: '{
      "type": #{GOOGLE_TYPE}
      "project_id": #{GOOGLE_PROJECT}
      "private_key_id": #{GOOGLE_PRIVATE_KEY_ID}
      "private_key": #{GOOGLE_PRIVATE_KEY}
      "client_id": #{GOOGLE_CLIENT_ID}
      "client_email": #{GOOGLE_CLIENT_EMAIL}
    }'

I tried these ways too but it did not work.

<%= ["GOOGLE_TYPE"] %> and <%= "GOOGLE_TYPE" %>

Error:
unexpected token at '{ "type": #{GOOGLE_TYPE} "project_id": #{GOOGLE_PROJECT} .....

Any help would be appreciated.

CodePudding user response:

First, isn't secrets.yml a Rails 4 thing? (you've tagged with the Rails 3 tag, so I'm guessing you're using 3?)

Second, fairly sure you need the environment at the top level, like in database.yml.

Third, you access the keys within the env with Rails.application.secrets.the_key

  • Related