vinceh
vinceh

Reputation: 3510

Rail 3 Custom Environment Variables

How do we create custom environment variables in Rails 3.1?

For example, in my mailer I might want to send an email from [email protected] during development mode but I want to send an email from [email protected] during production.

I tried something like this but got an error saying the variable was not initialized.

Thanks :)

Upvotes: 0

Views: 708

Answers (1)

Kyle
Kyle

Reputation: 22258

In your environment files, add a variable

app/config/environments/development.rb

YourApp::Application.configure do
  # other stuff... 
  config.admin_email = "[email protected]"
end

app/config/environments/production.rb

YourApp::Application.configure do
  # other stuff... 
  config.admin_email = "[email protected]"
end

Depending on the environment, YourApp::Application.config.admin_email will contain either [email protected] or [email protected]

Alternatively, if the emails only differ by the environment name, I would suggest doing something like this...

admin_email = "admin_#{Rails.env}@gmail.com"

Upvotes: 5

Related Questions