I want to save email account information in config.yml file. I load this information into a constant in the Rails configuration / initialization file, following the general pattern that I saw on the Internet, and outlined in this RailsCast . I am trying to set default values ββfor Action Mailer using config.action_mailer.smtp_settings inside the config / application.rb file, following the example of Mat Harvard Blog . I keep getting uninitialized persistent errors when starting my rails server. I assume application.rb is called before the configuration / initializers. Is there any other place where I can set config.action_mailer.smtp_settings during startup, but after running configuration / initializers?
Update: Perhaps I was not clear from my original question / question. I am reading the config.yml file in the initializer. This configuration file stores email account information such as username and password. I do not want to put this information (username and password) in application.rb or environment.rb files. I tried to move my code to the environment.rb file, but ran into the same uninitialized persistent error when starting the rails.
My code for setting up the mail program is as follows:
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 am reading from the config.yml file to set the APP_CONFIG constant in the load_config.rb initializer. This file contains two lines below:
raw_config = File.read(RAILS_ROOT + "/config/config.yml") APP_CONFIG = YAML.load(raw_config)[RAILS_ENV]
source share