應用程序配置,我想從數據庫中加載一些配置設置時,我的Rails(3.2.13)應用程序啓動:裝載軌從數據庫
class MyApp < Rails::Application
#...normal config here...
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => SystemSetting.system_smtp_host,
:port => SystemSetting.system_smtp_port,
:user_name => SystemSetting.system_smtp_username,
:password => SystemSetting.system_smtp_password,
:authentication => SystemSetting.system_smtp_authentication,
:enable_starttls_auto => SystemSetting.system_smtp_enable_starttls_auto }
end
但現在看來,該數據庫的配置尚未閱讀在此刻。我收到一個錯誤:
ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
我該如何做到這一點?要麼讓Rails首先初始化數據庫配置,要麼......還有其他的東西?
您可能要暫停,並考慮使用,而不是從數據庫中值的環境變量。我一路走下坡路,非常喜歡環境變量。以這種方式設置的開發環境得到了dotenv gem的大力支持:https://github.com/bkeepers/dotenv – pdobb
可能,但這更多的是CMS,我認爲配置全部可編輯,並且在一個位置可以簡化事情到最後。我會看看你的建議。謝謝。 –