18

I am trying to open credentials file with this command.

rails credentials:edit

It returns :

No $EDITOR to open file in. Assign one like this:

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

For editors that fork and exit immediately, it's important to pass a wait flag, otherwise the credentials will be saved immediately with no chance to edit.

So I make this command :

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

However, terminal responds with "New credentials encrypted and saved" without opening an editor.

1

8 Answers 8

12

Are you using the correct alias for wait? In official documentation there is:
-w or --wait: Wait for the files to be closed before returning

So it should be:
EDITOR="subl --wait" bin/rails credentials:edit.

I've just tested this on ubuntu with vs code, and atom and it worked correctly:
EDITOR="code --wait" rails credentials:edit.
EDITOR="atom --wait" rails credentials:edit.

Also check if subl is correctly added to system variable path.

2
  • 2
    Yes I did it didn't change , i get the same issue
    – Emma.D
    Commented Sep 17, 2018 at 15:43
  • yes i try it by credentials are not saving Commented Apr 7, 2021 at 7:31
7
EDITOR="vim" rails credentials:edit

example using any environment:

EDITOR="vim" rails credentials:edit --environment=production
4

As a VS Code user, this took me a while to figure out. What was missing to install the code command through VS Code's interface.

Crossposting Bryan's answer here:

  • Launch VS Code.
  • Open the Command Palette (⇧⌘P) and type shell command to find the Shell Command: Install code command in PATH command.
  • Now run EDITOR="code --w" bin/rails credentials:edit

There might be a similar missing step for Sublime users.

1
  • Thank you @Thomas, I was facing the same problem and found that code command was not installed in VS editor. It's working fine for me. Commented Oct 18, 2023 at 10:36
2

For all the Windows 10/11 users: setup the editor using the following command:

$env:EDITOR="notepad"

Now run this command to edit the credentials file:

bundle exec rails credentials:edit --environment development
1
  • I get "The filename, directory name, or volume label syntax is incorrect." when I try your first command. Perhaps this needs to be run in a particular folder? I am in my project's root folder, though...
    – MSC
    Commented Apr 28 at 0:41
1

If you want to run vim inside of a devcontainer:

sudo apt update
sudo apt install vim

EDITOR="vim --nofork" bin/rails credentials:edit
1
  • 1
    thank the stars for you.. really happy to have vim editing for this. nofork.. should have known. thanks!
    – trh
    Commented Jun 8, 2022 at 19:48
0

As nuaky answered, the following command helps me (assume terminal command line in app folder):

$ EDITOR="subl --wait" rails credentials:edit

0

I know this is an old question but I spent a good hour trying to get this answer. The following worked for me

MAC - Catalina 10.15.4
Rails Version= 6.0.3.2
Ruby Version= 2.7.0

I run on the terminal

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

And it allowed me to edit the credentials.yml.enc file.

0

I had this issue fixed by setting my editor to sublime text in the terminal like this:

export EDITOR="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -w"

Then running rails credentials:edit again

-w will make sure that changes are saved when you exit the editor.

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.