Sunday, 10 November 2019

Credentials in Rails 5.2 and Rails 6 Multi Environment credentials support

 Rails 5.2 - Supports credentials , But Not support Multi Environment

credentials are stored in the file config/credentials.yml.enc

and this file is encrypted by the key located inside
config/master.key.

How to achieve multi-environment feature in rails 5.2 is



module YourAppModule
  class Application < Rails::Application
    def credentials
      if Rails.env.production?
        super
      else
        encrypted(
          "config/credentials.#{Rails.env.downcase}.yml.enc",
          key_path: "config/#{Rails.env.downcase}.key"
        )
      end
    end
  end
end