3

I am a beginner programmer who is currently practicing with the Sinatra gem.

One of my projects is a simple weather app that tells users the weather in different cities. Now I would like to hide the API key I've been using, since I want to upload this site to Heroku. How do I go about doing that? I know that I will need a config.yml file. Where does this go? Does it need to go into a certain folder?

It is just as simple as sticking this in the config.yml file?

    weather_api_key: *api key here*

Will I need to put any additional commands in my server.rb file?Can anyone give me any pointers here?

2 Answers 2

5

There are a couple of ways you can do that.

One is to use a file, which you'd add to your gitignore, the other is to use a environment variable, and then refer to that in your config file:

in ~/.bash_profile:

export WEATHER_API_KEY=*api key here*

in config.yml:

WEATHER_API_KEY: <%= ENV['WEATHER_API_KEY'] %>

You'll need to either manually refresh your bash settings (. ~/.bash_profile), or close your terminal window and open a new one for the environment variable to be properly set.

1
  • You're welcome :) Please accept the answer if it works you
    – magni-
    Apr 7, 2016 at 4:42
0

Use environment variables

Heroku recommends this too

Try this too

2
  • 1
    Thanks for the info, especially about the Heroku instructions! Apr 5, 2016 at 4:58
  • Please don't simply post links to other pages, as these links can become invalid over time. Provide the necessary context so that your answer does not need these external references. See the "Provide context for links" section (and others) in stackoverflow.com/help/how-to-answer
    – To마SE
    May 16, 2016 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.