Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8163109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:56:51+00:00 2026-06-06T18:56:51+00:00

My personal rails project uses a few API’s for which I store the API

  • 0

My personal rails project uses a few API’s for which I store the API keys/secrets in config/environments/production.yml and development.yml as global variables. I now want to push this project to github for others to use, but I don’t want them to have those bits of sensitive data. I also don’t want this file in .gitignore because it’s required for the app to run. I’ve considered putting them in the DB somewhere, but am hoping to find a better solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:56:52+00:00Added an answer on June 6, 2026 at 6:56 pm

    TLDR: Use environment variables!

    I think @Bryce’s comment offers an answer, which I’ll just flush out. It seems one approach Heroku recommends is to use environment variables to store sensitive information (API key strings, database passwords). So survey your code and see in which you have sensitive data. Then create environment variables (in your .bashrc file for example) that store the sensivite data values. For example for your database:

    export MYAPP_DEV_DB_DATABASE=myapp_dev
    export MYAPP_DEV_DB_USER=username
    export MYAPP_DEV_DB_PW=secret
    

    Now, in your local box, you just refer to the environment variables whenever you need the sensitive data. For example in database.yml :

    development:
      adapter: mysql2
      encoding: utf8
      reconnect: false
      database: <%= ENV["MYAPP_DEV_DB_DATABASE"] %>
      pool: 5
      username: <%= ENV["MYAPP_DEV_DB_USER"] %>
      password: <%= ENV["MYAPP_DEV_DB_PW"] %>
      socket: /var/run/mysqld/mysqld.sock
    

    I think database.yml gets parsed just at the app’s initialization or restart so this shouldn’t impact performance. So this would solve it for your local development and for making your repository public. Stripped of sensitive data, you can now use the same repository for the public as you do privately. It also solves the problem if you are on a VPS. Just ssh to it and set up the environment variables on your production host as you did in your development box.

    Meanwhile, if your production setup involves a hands off deployment where you can’t ssh to the production server, like Heroku’s does, you need to look at how to remotely set up environment variables. For Heroku this is done with heroku config:add. So, per the same article, if you had S3 integrated into your app and you had the sensitive data coming in from the environment variables:

    AWS::S3::Base.establish_connection!(
      :access_key_id     => ENV['S3_KEY'],
      :secret_access_key => ENV['S3_SECRET']
    )
    

    Just have Heroku create environment variables for it:

    heroku config:add S3_KEY=8N022N81 S3_SECRET=9s83159d3+583493190
    

    Another pro of this solution is that it’s language neutral, not just Rails. Works for any app since they can all acquire the environment variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on my personal rails project and I'm still learning a lot of
I recently started working on a small personal project in Ruby on Rails, and
So I've got a form in my Rails app which uses a custom FormBuilder
I built a small cms for personal websites using Rails. Each site has a
I'm doing a personal number-crunching project, and I'd like to launch multiple programs on
I have a personal project I'm planning and I came to a small hurdle.
The specs for my rails project have been really slow lately. I did a
I am creating a small rails app for personal use and would like to
i've developed small web app for personal use with Ruby on Rails. Now when
I'm building a small personal web app in Ruby on Rails. I've set it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.