How to generate the config / secrets.yml file in Rails?

0

It turns out that I just started a project in RoR and my project does not contain the file secrets.yml, I would like to know how to generate one or make the original appear that should be hidden somewhere.

    
asked by Upset Grade 18.08.2018 в 16:31
source

3 answers

1

The secret is no longer generated in rails 5 now other files are used, if your rails is greater than 5 then you will need to use the command EDITOR="vim" bin/rails credentials:edit the value of your EDITOR can also be nano depends on which one you have installed EDITOR="nano" bin/rails credentials:edit .

If your rails is less than 4 then here is an example of your secrets:

development:
  secret_key_base: super_long_secret_key_for_development
  active_merchant_login: 896667
  active_merchant_password: supersecretpassword888

test:
  secret_key_base: super_long_secret_key_for_test
  active_merchant_login: 896667
 active_merchant_password: supersecretpassword888

production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  active_merchant_login: <%= ENV["AM_LOGIN"] %>
  active_merchant_password: <%= ENV["AM_PASSWORD"] %>

I took it from this league

    
answered by 18.08.2018 / 21:56
source
0

Additionally, in the production environment you must create the environment variable SECRET_KEY_BASE and assign it a key generated by the rails secret command.

C: > rails secret 175501ea97a18f4f153b0f8df3c10a3ce97f09871bb5eb88c5ae9998b1a089c06bff6f88eb57bc94a8ff1d635ff0fa7a58df108e7e7d10c664f9234862a13714

    
answered by 20.09.2018 в 01:56
0
  • How credentials are used in Rails 5.2 Spotify API example:

    • To consume the Spotify data it is necessary to register the App that we developed, you can do it in the following link Spotify
    • When using Ruby on Rails 5.2, we have to add the access data of the app that we registered, to the file "../config/credentials.yml.enc" that means the "Client ID" and the "Client Secret"
    • To modify the file "../config/credentials.yml.enc", in the terminal (or command line) we must be located in the project directory and execute the command EDITOR=nano rails credentials:edit , then add the data of the «Client ID» and the «Client Secret»
    • It should look similar to the following

      development:
        spotify:
         access_key_id: abc123
         secret_access_key: abc123  
      
      production:
        spotify:
          access_key_id: abc123_
          secret_access_key: abc123_  
      
    • "../ config / master.key" must be added to ".gitignore" as the decryption key.

This answer is extracted from another question, the complete example with the API of spotyfy is in this link

    
answered by 02.01.2019 в 06:18