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?

Leia_Organa
  • 1,894
  • 7
  • 28
  • 48

2 Answers2

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.

magni-
  • 1,934
  • 17
  • 20
0

Use environment variables

Heroku recommends this too

Try this too

Community
  • 1
  • 1
maxadorable
  • 1,290
  • 1
  • 10
  • 24
  • 1
    Thanks for the info, especially about the Heroku instructions! – Leia_Organa Apr 05 '16 at 04: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 http://stackoverflow.com/help/how-to-answer – To마SE May 16 '16 at 18:47