Reputation: 52238
I currently have this in every controller action that needs it (quite a few):
Stripe.api_key = Rails.application.credentials[Rails.env.to_sym][:stripe][:secret_stripe_test_key]
Where is the best place to put this code? The options that come to mind are:
before_action
, and run that before the controller actions that need itinitializer.rb
file and have it run once on the application startWhat I currently have isn't DRY, so I figured there's got to be a better way.
Upvotes: 1
Views: 1471
Reputation: 2344
I prefer the approach mentioned here Stripe on Ruby on Rails - Creating config/initializers/stripe.rb You can then have the values in environment variables. This is safer when in production
Upvotes: 1
Reputation: 2399
You can create an intializer file inside folder config/initializers/stripe.rb
and put this key there
Stripe.api_key = Rails.application.credentials.stripe_secret_key
Upvotes: 4