Home > Net >  Rails 6: How do I create credentials that work in both dev and test but not production without dupli
Rails 6: How do I create credentials that work in both dev and test but not production without dupli

Time:10-19

I have created a file to hold development credentials by running

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

So, for example, I can access Rails.application.credentials.vonage in dev.

However, doing the same in test, I get nil:

> Rails.application.credentials.vonage
=> nil

How do I set up shared credentials for dev and test but not production without duplication?

CodePudding user response:

You can configure your test environment to look for the development file and key.

# config/environments/test.rb
Rails.application.configure do |config|

  ...

  config.credentials.content_path = Rails.root.join("config/credentials/development.yml.enc")
  config.credentials.key_path = Rails.root.join("config/credentials/development.key")

  ...

end

See Rails General Configuration for more.

  • Related