Save 36% for Black Friday! Learn more

All threads / Rails for Beginners Part 23: Rails Credentials Discussion
Ask A Question

Notifications

You’re not receiving notifications from this thread.

Rails for Beginners Part 23: Rails Credentials Discussion

When I try to do rails credentials:edit I get the following error

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

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

I did copy and paste what it said to do but it still didn't work

You need to specify your editor to open the credential file. Here is some options depends on you;

EDITOR=vim
EDITOR=code
EDITOR=sublime
EDITOR=atom

You also can do like this;

EDITOR=vim rails credentials:edit --environment=development

This worked for me:
EDITOR=”code --wait” rails credentials:edit --environment=development

Reply

This seems like you don't have mate shell support for TextMate editor in your terminal. You need to install mate shell command by:
export EDITOR="/usr/local/bin/mate -w"
The path above mentioned is according to my machine. Alternate, you can install shell support from your TextMate editor by:
Preferences > Terminal > Install

After that, you are good to go
EDITOR="mate --wait" bin/rails credentials:edit

Thank you all that was it. I guess the question is how to do it permanently? Each time I have to start the editor

Yeah, it always is going to ask you for the command, you can type

EDITOR="code --wait" rails credentials:edit --environment=development

it opens in vscode, you need to set up your variables save and close the file in order to be saved and encrypted.

Reply

On OSX and linux:

For VS Code, run:
EDITOR="code --wait" rails credentials:edit

For Atom, run:
EDITOR="atom --wait" rails credentials:edit

In linux this Editor="code --vait" rails credentials:edit --environment=development , helped a lot , thanks @mikeHatfield, saved a lot of my time in this quest.

Reply

Hi Cris, thanks for the help. I do not know with your are going to explain how to set a heroku and twitter account, but I think it is not very difficult, because I've already did the twitter part but I do not have a heroku yet, so I will try to do this tutorial and maybe when I finished I have the knowledge.

Reply

Twitter is lame =(
"Your application has been reviewed. Thank you for your interest. Unfortunately, we’re unable to to approve your application."

Reply

I had a weird issue where running the "rails credentials:edit --environment=development" command (from the integrated terminal in VSCode) would open up a new development.yml file instead of the existing one with the commented out aws credentials that is pre-populated by Rails.

This was resulting in me getting a 400 error from OmniAuth because Rails.application.credentials was returning nil.

I spent ages chasing my tail and looking into all kinds of other things before coming across:

https://github.com/rails/rails/issues/37427

It turns out that running the below command forced Rails to open the correct file to edit rather than create a new one and I was good to go!

EDITOR='code --wait' rails credentials:edit --environment=development

The fix to ensure that you won't have to do this again in future is to make sure that in any file where you may have specified VSCode to be your default editor e.g. your .zprofile etc. you need to make sure that you add the wait flag!

In my case, I had: export EDITOR="code" and this fixed it: export EDITOR="code -w".

You may want to apply this to your global .gitconfig file while you're at it:

[core]
editor = code --wait

Thank you so much Marco. Your help saved me lots of time and energy.
Good luck.

Reply

Hello, when I run
Rails.application.credentials.twitter
I can't seem to find my application credentials and all the blogs don't seem to help.
When I write ls config/credentials I seem to find my files, but when I try to log them on the Rails Console. I can't seem to find them. Please help really frustrated.

Reply

I don't have the file opening up once I run the command. So I do not know how to save the API keys, and because of that, I cannot make any progress.

Reply

Thank you for any help
Issue : Rails Credentials
What am I attempting to do: Add Twitter Api_key & Api_key_secret key to my rails app using the rails credentials:edit --enviroment=developement command.
environment details: editor Atom
list of errors and attempts to resolve them:
ran: rails credentials:edit --enviroment=developement
traceback:`edit': wrong number of arguments (given 1, expected 0) (ArgumentError)
ran: EDITOR="atom --wait" rails credentials:edit
which: creates a ####.credentials.yml file, but the command line is now left hanging. I am not able to exit and save any edits to the file. Forcing me to control + c to make the command line usable again.
Thank you for your help

Reply

This seems like you don't have mate shell support for TextMate editor in your terminal.

You need to install mate shell command by:

export EDITOR="/usr/local/bin/mate -w"
The path above mentioned is according to my machine.

Alternate, you can install shell support from your TextMate editor by:
Preferences > Terminal > Install

After that, you are good to go
EDITOR="mate --wait" bin/rails credentials:edit


Reliable Permit Solutions, LLC

Reply

How to deploy app to heroku?

Reply

This App has violated Twitter Rules and policies. As a result, certain functions will be limited.
Out of all the amazing APIs you could have used , you went ahead and picked messy Twitter :(

Reply

Maybe this part of the course explains all we need to don't get stuck and make some progress. I put my application on Twitter, hope all gonna fine. But if don't what is the alternative to work and keep with the course?

Reply

I am able to add the tokens to the development.key file. when I go to the rails console to test that the keys are there, I get an error "`rescue in _decrypt': ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)"

Any one know how I can fix?

Reply

I got "nil" when using Rails.application.credentials.twitter but restarted my editor - Rubymine and it worked. :)

Reply
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 67,819+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.