I want to store email account information in a config.yml file. I'm loading that information into a constant in a Rails config/initializers file following a common pattern I've seen online and outlined at this RailsCast. I'm trying to setup defaults for Action Mailer using config.action_mailer.smtp_settings inside the config/application.rb file, following an example on Mat Harvard's Blog. I keep getting uninitialized constant errors when starting my rails server. I'm assuming that application.rb is being called before the config/initializers. Is there another location where I can set the config.action_mailer.smtp_settings during startup, but after the config/initializers run?
Update: I may not have been clear in my initial post/question. I'm reading the config.yml file in an initializer. This config file stores email account information such as username and password. I don't want to put this information (username and password) in either the application.rb or environment.rb files. I did try moving my code to the environment.rb file, but encountered the same uninitialized constant error when starting rails.
My code to set the action mailer settings looks like this:
config.action_mailer.smtp_settings = {
:address => APP_CONFIG[:email_config][:address],
:port => APP_CONFIG[:email_config][:port],
:domain => APP_CONFIG[:email_config][:email_domain],
:user_name => APP_CONFIG[:email_config][:user_name],
:password => APP_CONFIG[:email_config][:password],
:authentication => :plain,
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = {
:host => APP_CONFIG[:email_config][:host]
}
I'm reading from the config.yml file to set the APP_CONFIG constant in a load_config.rb initializer. That file contains the 2 lines below:
raw_config = File.read(RAILS_ROOT + "/config/config.yml")
APP_CONFIG = YAML.load(raw_config)[RAILS_ENV]