I can’t access env variables in the Rails console, while in the application they work.
In .powenv I have export SENDGRID_PASSWORD="123"
In config/initializers/mail.rb there is:
ActionMailer::Base.smtp_settings = {
:password => ENV['SENDGRID_PASSWORD']
}
So in the console when I type UserMailer.welcome_mail.deliver there is an error ‘ArgumentError: SMTP-AUTH requested but missing secret phrase’. However from the application it sends the mail successfully.
How can I make the env variables available in the console?
Your Rails console isn’t able to access the environment variable because Pow passes information from the
.powenvor.powrcfile into Rails … Rails doesn’t read those files on its own.In other words, you’re setting the
ENV['SENDGRID_PASSWORD']variable in the.powenvfile, but that file is not being touched when you start the Rails console.You’ll need to set up a
before_filterin your Application Controller that sets theENV['SENDGRID_PASSWORD'](or come up with another, similar, way of reading in the.powenvfile from within thatbefore_filterin your Rails app).