Skip to content

Read config settings from environment.rb

January 21, 2011

Perhaps there is a much easier way to do this, but I couldn’t find it.

I simply wanted to retrieve the values defined in the following actionmailer config block (why is another story :)):

config.action_mailer.smtp_settings = {
:address => "REDACTED",
:port => '25',
:domain => "devicemagic.com",
:authentication => :plain,
:user_name => "REDACTED",
:password => "REDACTED"
}

It’s actually as simple as:
ActionMailer::Base.smtp_settings[KEY]

So for the :address it would be:

ActionMailer::Base.smtp_settings[:address]

I didn’t find much in the way of docs about how Rails config actually propagates into the various subsystems, but clearly there is a larger reusable pattern here. I guess people tend to store custom-defined settings in YAML files, as in Ryan Bates’ Railscast?

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: