14

When I do bin/rails credentials:edit my editor opens a file like credentials.yml.enc.1234 with default content. After I'm done editing, I hit save, and the console reads New credentials encrypted and saved.

After I run bin/rails credentials:edit again, another temp file gets opened (credentials.yml.enc.4321) and the contents are back to default.

How can I make the credentials persist?

The Whiz of Oz
  • 6,763
  • 9
  • 48
  • 85

7 Answers7

28

If you aren't using vim, you need to add a wait flag to the editor.

e.g for atom:

EDITOR="atom --wait" rails credentials:edit

I ran into the same thing and found the answer here.

Peter T.
  • 8,757
  • 3
  • 34
  • 32
caroline
  • 588
  • 6
  • 9
4

I also had this problem with using atom as editor. I have tried:

EDITOR="atom --wait" rails credentials:edit

and

EDITOR="atom -w" rails credentials:edit

but no results. Finally, I used nano (ubuntu):

EDITOR="nano" rails credentials:edit

For me, this works fine. Maybe, it will be helpful for someone, as an alternative.

barmic
  • 1,042
  • 7
  • 15
3

There is an issue related to this: https://github.com/rails/rails/issues/31286

It's been fixed already in 5.2.0.rc1

Strangegroove
  • 250
  • 4
  • 6
3

I had this problem in rails 5.2.0 using textmate as the editor. It turns out the credentials file must be closed after save in order for the changes to persist.

tomb
  • 1,374
  • 1
  • 13
  • 23
1

You can use the following for opening the credentials file in sublime.

EDITOR="subl --wait" bin/rails credentials:edit

Make sure you close the credentials file in sublime after making the changes. Also restart your server to view the changes.

srijan439
  • 401
  • 5
  • 7
0

I have struggled a bit with this one due to the fact that I was not capitalizing EDITOR. The commmand

editor="vim" rails credentials:edit

directly saves the credentials without opportunity to edit. The guidance tells you to add the --wait flag. To me, it was not about the --wait flag but about the capitalization. This was working:

EDITOR="vim" rails credentials:edit

(no --wait flat but capitalized EDITOR)

Bastien
  • 596
  • 1
  • 11
  • 30
0

I had some trouble myself, eventually got it all working with TextEdit on OS X.

EDITOR="open -a TextEdit --wait" rails credentials:edit

That opens the editing but after saving and closing the file, I still didn't get the changes persisted. I needed to also quit TextEdit.

So if you want to use TextEdit to edit credentials on OS X Ventura you can do it with the above command, then save the file, then quit TextEdit.

wuliwong
  • 4,238
  • 9
  • 41
  • 69