I am trying to set up a Stripe payment form for a Rails 6 project, and I am not able to access my stripe secret keys. I am getting an error NoMethodError (undefined method `[]' for nil:NilClass)
What am I doing wrong?
Here's what I did
Edit my credentials.yml.enc - Type this in the console EDITOR="code --wait" bin/rails credentials:edit
Added my secret keys to credentials.yml.enc
some_variable: secret_stuff
development:
stripe:
stripe_public_key: fake_key
strip_secret_key: fake_key
Closed the file and double checked it saved my code by opening up the file to verify it was saved (it was)
Open up rails console and typed in Rails.application.credentials.some_variable
I expected secret_stuff
but I got nil
.
Typed in Rails.application.credentials.development[:stripe][:stripe_public_key].
I expected fake_key
but I got NoMethodError (undefined method `[]' for nil:NilClass)
WHAT AM I DOING WRONG?
I can't display a credit card form, and I just want to get this up and running so I can charge people and become a millionaire.
You probably accessing credentials environment wrong, this should work:
Rails.application.credentials[Rails.env.to_sym][:stripe][:stripe_public_key]
credentials.development
=> credentials[Rails.env.to_sym]
(so you are accessing current environment varbiales)
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