Reputation: 13418
I'm building an application that send an e-mail to admin recipient. In development, it has a value of [email protected] and in production it have [email protected] . What is the best way to configure this kind of things in Rails? I want to use something like this:
mail(to: my.delivery.mail, :subject "whatever")
Thanks
Upvotes: 0
Views: 61
Reputation: 16435
Using environment variables
mail(:to => ENV['ADMIN_ADDRESS'], :subject => "whatever")
you then set them on deployment (through capistrano or whatever tool). This information is not business logic (so it does not belong to the app) nor business data (so it does not belong to the database). That's what environment is for.
Upvotes: 1
Reputation: 6942
If there are multiple environment you can set a method(mainly in mailer class) and set admin recipient,
or write into environments file config.admin_mail [email protected]
and in mail(to: AppName::Application.config.admin_email,..)
Upvotes: 0
Reputation: 2916
There are various ways, but the simplest is:
recipient = Rails.env.production? ? '[email protected]' : '[email protected]'
mail(to: recipient, :subject "whatevs...")
Upvotes: 2