【问题标题】:Rails 4.1 and exception_notification-rake gem causing uninitialized constant ExceptionNotificationRails 4.1 和 exception_notification-rake gem 导致未初始化的常量 ExceptionNotification
【发布时间】:2014-05-22 11:42:14
【问题描述】:

我已经升级到 Rails 4.1 并且正在尝试设置 exception_notification-rake gem 以通过电子邮件通知我失败的 rake 任务。

在我的 Gemfile 中,我有 gem 'exception_notification-rake'

development.rb,我有以下内容:

MyApp::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  # Specify what domain to use for mailer URLs
  config.action_mailer.default_url_options = {host: "localhost:3000"}
  config.action_mailer.smtp_settings = {
      :address              => 'smtp.gmail.com',
      :port                 => 587,
      :domain               => 'gmail.com',
      :user_name            => Rails.application.secrets.email['user'],
      :password             => Rails.application.secrets.email['pass'],
      :authentication       => 'login',
      :enable_starttls_auto => true
  }

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations
  config.active_record.migration_error = :page_load

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

  config.after_initialize do
    Bullet.enable = true
    Bullet.alert = true
    Bullet.bullet_logger = true
    Bullet.console = true
    # Bullet.growl = true
    Bullet.rails_logger = true
    Bullet.add_footer = true
  end

  config.middleware.use ExceptionNotification::Rack,
    :ignore_if => lambda { |env, exception| !env[:rake?] },
    :email => {
      :sender_address => %{"notifier" myemail@gmail.com},
      :exception_recipients => %w(myemail@gmail.com)
    }
    ExceptionNotifier::Rake.configure
end

如您所见,我使用 Rails 4.1 的 secrets.yml 文件传递​​用户和密码。 当我尝试启动我的 Rails 服务器时,我收到以下错误:

/development.rb:52:in `
block in <top (required)>': uninitialized constant ExceptionNotification (NameError)

我猜这是 exception_notification-rake gem 中的一个错误,它调用了 exception_notification 的早期版本,但我不确定。对此的任何帮助将不胜感激!

谢谢:)

更新:

我已经 notified the exception_notification-rake gem developer 关于这个。我有所有必备的 gem 并且有一个相当普通的设置,所以我认为这可能是 Rails 4.1 需要修复的一个错误

【问题讨论】:

  • 这是一个很明显的问题,但你确定你运行了bundle updatebundle install 并且你的gemfile 中有gem 'exception_notification' 以及gem 'exception_notification-rake 吗?
  • 是的,完成了所有这些。还是不行,谢谢

标签: ruby-on-rails actionmailer exception-notification


【解决方案1】:

issue 中可以看出,ExceptionNotification 的当前发布版本不适用于 rails 4.1

在新版本发布之前,您可以只使用主版本。在您的 Gemfile 中包含您的 gem,如下所示:

gem 'exception_notification', github: 'smartinez87/exception_notification'

维护者发布了一个rc-version,你可以使用如下

gem 'exception_notification', '4.1.0.rc1'

一旦新的 gem 版本发布,您可以切换到已发布的版本(4.1.0)。我猜这应该不会花太长时间;)

【讨论】:

  • 当我尝试将 gem 'exception_notification', github: 'smartinez87/exception_notification' 添加到我的 Gemfile 时,我收到以下错误:Bundler could not find compatible versions for gem "exception_notification": In Gemfile: exception_notification-rake (&gt;= 0) ruby depends on exception_notification (~&gt; 3.0.0) ruby
  • 您还必须更新您的exception_notification-rake 版本。注意:现在两个gem都已经发布了,所以你不用再去github,安装最新版本(4.0.1)就行了。我相应地更新了我的答案。
  • 好的。我弄错了(4.0.1 和 4.1.0 看起来很相似)。你似乎有一个旧版本的exception_notification-rake。我看到当前版本(0.1.2)取决于exception_notification 和版本~&gt; 4.0.1 所以我希望这会起作用(~&gt; 意味着只允许进行微小的更改,不破坏)所以我不确定它是否会支持4.1.0.rc 版本。我猜它没有,所以 gem 作者应该放宽这种依赖(例如,改用&gt; 4.0.1),或者发布一个新版本。
  • 我是exception_notification-rake的维护者。感谢您跟踪此问题。我推送了一个新版本 (0.2.0.rc1),它重新调整了依赖项以与 Rails 4.1 和 exception_notification 4.1 一起使用。
猜你喜欢
  • 1970-01-01
  • 2014-12-22
  • 1970-01-01
  • 2011-09-10
  • 1970-01-01
  • 2015-12-27
  • 1970-01-01
  • 1970-01-01
  • 2011-08-30
相关资源
最近更新 更多