Munkith Abid
2 min readNov 14, 2021

--

Getting cloned Ruby on Rails with credentials to work locally

Recently I cloned a project from github and tried to modify it. The project is built using Ruby on Rails 6.1. It was my project that I’ve made a while a go and then deleted from my local machine, and when that time’s come I decided to do some modifications to the project and add some enhancements. After cloning the repository from github and tried to run the server I received a long load error the end of which reads something like this:

/home/.../.rvm/gems/ruby-2.6.1/gems/bootsnap-1.7.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': cannot load such file -- .../config/environment (LoadError)

Now that wasn’t expected. Especially from a project that I own. Little I knew at that time that when first building new Ruby on Rails project using the command;

$ rails new my_api --api

It actually creates(among other things) two security related files,

one called

master.key

and the other is

credentials.yml.enc

Now this works fine when you create the app the first time. But if you push to github and later on you clone it down on your machine, you’ll simly run through a variation of the error mentioned above. And the reason is simple. The master.key file is ignored by git and will (and should) never be pushed to a public repository as it contains the private key to your application credentials which contains among other thing your Rails application’s

secret_key_base

That key will become essential once you get to think about security aspects of the application, like when incorporating Devise and/or JWT .

Now let’s get to the solution of the problem this short article is about, which is surprisingly simple.

Once you done cloning the repo from it’s remote origin, you simply need to do two things:

  1. Make sure you delete the credentials.yml.enc file in the app/config/initializers directory if it exists.
  2. Run the following command in the terminal:
EDITOR="code --wait" rails credentials:edit

Note: the ‘code’ word in the command refers to vscode as the editor to use to open the credentials.yml.enc when rails finished creating it.

This command will create credentials.yml.enc and it’s associated master.key for this specific copy of rails application, and baisically all you need to get your app running.

--

--