I’m trying to work on a Rails site here in it’s development environment, where I want to test email delivery, and I can’t work out why properties declared in the main environment.rb aren’t being overwritten by the more specific development.rb file that I presume would be loaded when booting a rails app.
My understanding here is that values in more specific environment config files like this should override the shared ‘environment.rb’ config file, so if I have declared some email settings like so in config/environment.rb…
ActionMailer::Base.smtp_settings = {
:address => 'smtp.hostingcompany.com',
:port => 25,
:domain => 'productiondomain.net',
:authentication => :login,
:user_name => "productiondomainmailer",
:password => "TOP_SEKRIT"
}
… then code here in config/environments/development.rb below should override the ActionMailer:Base.smtp_settings hash:
ActionMailer::Base.smtp_settings = {
:domain => 'developmentdomain.net'
}
However, when load the app in the development environment, or from script/console to check the value of ActionMailer::Base.smtp_settings[:domain], it’s still listed as ‘productiondomain.net’.
Why might this happening?
To set the configuration for your development environment put:
rather than:
in config/environments/development.rb
Note that in config/environments/development.rb you will need to specify the full set of settings and not just
:domainas the hash overwrites the existing value rather than being merged with it.And similarly, set the default in config/environments.rb by putting
config.action_mailer.smtp_settings =inside theRails::Initializer.run do |config|block.