config.scoping == :important => true
Chris Brandhorst ma 01 mrt 10
Last week I realised that using the config scope in your Rails environment files can be quite important.
We had the situation that we needed a different SMTP configuration for different environments.
In the environment.rb I found the following lines:
Rails::Initializer.run do |config| ... end ActionMailer::Base.smtp_settings = { :address => "127.0.0.1", :port => 25, :domain => "hollandonrails.nl" }
For the develoment environment I needed something else, so I proceeded to add the following to development.rb:
ActionMailer::Base.smtp_settings = { :address => "mail.google.com", :port => 25, :domain => "bla.com" }
But then the emails were not sent in the dev environment. Not knowing the cause, I spent an hour or two figuring this out.
Finally, I found out that the ActionMailer settings given in development.rb were not used. Some more investigation revealed the following things:
- ActionMailer is not defined within the Rails::Initializer block in environment.rb
- Using ActionMailer inside development.rb does NOT raise an error, but the scope of development.rb seems to be the same Rails::Initializer block
- Setting ActionMailer settings using config.action_mailer (like below) does allow overriding of these settings
config.action_mailer.smtp_settings = { :address => "127.0.0.1", :port => 25, :domain => "hollandonrails.nl" }
Gepost in | 0 reacties
Welcome to Holland On Rails
This weblog is the official Ruby techblog from the guys at Holder, a Ruby development company. Holder is also the company behind the RubyAndRails Europe Conference in Amsterdam.Recente Jobs
Bekijk alle jobs »»
Gereedschapskist
Onmisbare tools vooriedere developer!
- Ruby On Rails
Framework voor de web 2.0 developer. Eindelijk vooruitgang! - TextMate
Editor for true pro's
Typ, tab, top :-)
Nee, niet voor Win. - Made On A Mac
En nou is het over met die saaie grijze Windows bak van je!
Auteurs op deze site
Chris Obdam
'Less is more' evangelist, past dit ook dagelijks toe op zijn tandenborstel.Chiel Wester
Snelheidswonder op Ruby wielen. Leuk om mee te pair-programmen ;-)
Plaats je reactie