Search code examples
ruby-on-railsenvironment-variablesomniauth

ENV variables loading as nil


I am trying to run omniauth. I have my initializer as follows:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :coinbase, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], scope: 'wallet:user:read wallet:user:email wallet:accounts:read'
end

with my client ID and secret saved in my .env file. When I boot my server, however, both of these variables are listed as nil. I can get the procedure to work when it is hard coded, but this is obviously not a good practice. How can I get the variables from my .env file into my initializer?


Solution

  • Problem was solved by leveraging the dotenv gem and following the instructions in the readme