我正在研究"学习Ruby on Rails"作者:Daniel Kehoe,我提出了这段代码:
在 config / environments / development.rb :
中config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: Rails.application.secrets.domain_name,
authentication: "plain",
enable_starttls_auto: true,
user_name: Rails.application.secrets.email_provider_username,
password: Rails.application.secrets.email_provider_password
}
# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
# Send email in development mode?
config.action_mailer.perform_deliveries = true
这让我想到了两个问题。
email_provider_username: <%= ENV["GMAIL_USERNAME"]
。为什么不直接在 config / environments / development.rb 文件中使用ERB?我能想到的唯一原因是development.rb没有通过ERB预处理器运行。是这样的吗?只是想在这里理解设计决策。 Rails
是一个对象。有人可以向我解释这是如何工作的吗?这是&#34; top&#34;我的rails应用程序? 答案 0 :(得分:0)
我相信这是以这种方式完成的,因为您不一定将它存储在开发和生产环境的环境变量中。对于development
,您可以直接将其存储在文件中,但对于production
,您可以将其存储在环境变量中,这样可以更灵活地执行此操作。
Rails
实际上是一个模块,而不是一个类。您可以通过查看Rails
源代码来了解其工作原理:
https://github.com/rails/rails/blob/master/railties/lib/rails.rb