繁体   English   中英

在Capistrano部署期间使用Rails 5,Ruby 2.4和Capistrano 3发送电子邮件

[英]Sending emails during Capistrano deployment using Rails 5, Ruby 2.4, and Capistrano 3

要具体说明Capistrano 3.7.2,Rails 5.0.2和Ruby 2.4.0。 我得到的错误是在Execute load:defaults之后发生的:

** Execute load:defaults
cap aborted!
NameError: uninitialized constant ActiveSupport::Rescuable
/Users/username/.rvm/gems/ruby-2.4.0/gems/actionmailer-5.0.2/lib/action_mailer/rescuable.rb:6:in `<module:Rescuable>'
/Users/username/.rvm/gems/ruby-2.4.0/gems/actionmailer-5.0.2/lib/action_mailer/rescuable.rb:4:in `<module:ActionMailer>'
/Users/username/.rvm/gems/ruby-2.4.0/gems/actionmailer-5.0.2/lib/action_mailer/rescuable.rb:1:in `<top (required)>'
/Users/username/.rvm/gems/ruby-2.4.0/gems/actionmailer-5.0.2/lib/action_mailer/base.rb:8:in `require'
/Users/username/.rvm/gems/ruby-2.4.0/gems/actionmailer-5.0.2/lib/action_mailer/base.rb:8:in `<top (required)>'
/Users/username/rails_5_test_app/config/deploy/notify/cap_mailer.rb:5:in `require'
/Users/username/rails_5_test_app/config/deploy/notify/cap_mailer.rb:5:in `<top (required)>'
config/deploy.rb:4:in `require'
config/deploy.rb:4:in `<top (required)>'
/Users/username/.rvm/gems/ruby-2.4.0/gems/capistrano-3.7.2/lib/capistrano/setup.rb:27:in `load'
/Users/username/.rvm/gems/ruby-2.4.0/gems/capistrano-3.7.2/lib/capistrano/setup.rb:27:in `block (3 levels) in <top (required)>'
/Users/username/.rvm/gems/ruby-2.4.0/gems/capistrano-3.7.2/lib/capistrano/configuration/variables.rb:32:in `untrusted!'
/Users/username/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/delegate.rb:83:in `method_missing'
/Users/username/.rvm/gems/ruby-2.4.0/gems/capistrano-3.7.2/lib/capistrano/setup.rb:26:in `block (2 levels) in <top (required)>'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
/Users/username/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/Users/username/.rvm/gems/ruby-2.4.0@global/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
/Users/username/.rvm/gems/ruby-2.4.0/gems/capistrano-3.7.2/lib/capistrano/application.rb:14:in `run'
/Users/username/.rvm/gems/ruby-2.4.0/gems/capistrano-3.7.2/bin/cap:3:in `<top (required)>'
/Users/username/.rvm/gems/ruby-2.4.0/bin/cap:22:in `load'
/Users/username/.rvm/gems/ruby-2.4.0/bin/cap:22:in `<main>'
/Users/username/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
/Users/username/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => staging

我即将开始将Rails 4应用程序升级到Rails 5,并决定做一个小型测试应用程序以确保我所有的宝石都在工作。 一切都很好,除了自从Rails 2在Capistrano部署期间发送电子邮件以来一直使用的代码,这在我尝试要求或加载邮件程序代码时导致此错误; deploy.rb的第4行是必需的。 如果我将其注释掉并设置一个不发送电子邮件的标记,则部署将完美工作。

邮件程序代码(基于MislavMarohnić几年前发布的内容):

cap_mailer.rb:

require "action_mailer"

yaml_config = File.read("config/email.yml")
email_config = YAML.load(yaml_config)
ActionMailer::Base.delivery_method = email_config['delivery_method'] # currently set to :smtp
ActionMailer::Base.smtp_settings = {
    address: email_config['smtp_settings']['address'],
    port: email_config['smtp_settings']['port'],
    notify_emails: email_config['notify_emails']
}
ActionMailer::Base.view_paths = File.dirname(__FILE__)

class CapMailer < ActionMailer::Base
  default :from => 'App Deployment <app_deploy@my.org>'

  def deploy_notification(cap_vars)
    @now = Time.now

    set :body, ENV['comment']

    mail(:to => fetch(:notify_emails),
         :subject => "#{fetch(:human_readable_application_name)} - Changes to application on #{fetch(:stage)} server at #{fetch(:host)}"
    )
  end

  def test_email
    @now = Time.now

    mail(:to => "developer@my.org",
         :subject => "#{fetch(:human_readable_application_name)} - Capistrano test email #{@now.strftime("on %m/%d/%Y at %I:%M %p")}"
    )

  end

end

我在网上可以找到的都是对非常相似的邮件设置的引用(例如https://gist.github.com/johnthethird/955917 ),它们是为所有旧版本编写的。 在Capistrano部署过程中,有几封要发送邮件的gem,但是它们确实存在着同样的问题( capistrano-notifiercapistrano_mailer )。

所以在这一点上,我被困住了。 Googling NameError: uninitialized constant ActiveSupport::Rescuable建议这可能是配置问题,但我不知道在那儿寻找什么。 ActiveSupport :: Rescuable IS在我的Rails安装中; 我仔细检查了。 任何想法,将不胜感激。

看起来您需要先加载ActiveSupport,如下所示:

require "active_support"
require "action_mailer"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM