I'm (still/always) new to Rails. While I was building my project Rails upgraded to v5.2 with encrypted credentials. Now I'm about to deploy to production and found that I do not understand how to separate production credentials from development. And I'm not sure that I know how I would do it in v5.1. So how to make it in Rails 5.2?
I solved my issue using this code
If in your credentials file like this
development:
stripe_secret_key: 123
production:
stripe_secret_key: 345
test:
stripe_secret_key: 678
1'st solution:
Rails.application.credentials[Rails.env.to_sym][:stripe_secret_key]
2'nd solution:
open application.rb file and define self.credentials method
module ModuleName
class Application < Rails::Application
def self.credentials
@credentials ||= Rails.application.credentials[Rails.env.to_sym]
end
end
end
And use
ModuleName.credentials[:stripe_secret_key]
More info please refer link
I've found the rails-env-credentials gem useful for this. Not sure how compatible it will be with the upcoming Rails 6 support but its been working great for my app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With