Ruby on rails 异常通知Gem和Rails 3

Ruby on rails 异常通知Gem和Rails 3,ruby-on-rails,exception-handling,ruby-on-rails-3,ruby-on-rails-plugins,Ruby On Rails,Exception Handling,Ruby On Rails 3,Ruby On Rails Plugins,我试图让它启动并运行,但每当我启动服务器时,我都会看到“未初始化的常量例外通知程序” 我的档案里有 gem“异常通知”,:git=>,:branch=>“master” 我尝试将github自述文件中所示的配置放在config/application.rb、config/environment.rb和config.ru中。我用我的应用程序名替换了“Whatever”。Rails 3似乎不能以gem的形式使用这个插件。也许机架应用程序无法从gems加载?我将其作为插件安装,并将配置语法更改为:

我试图让它启动并运行,但每当我启动服务器时,我都会看到“未初始化的常量例外通知程序”

我的档案里有

gem“异常通知”,:git=>,:branch=>“master”


我尝试将github自述文件中所示的配置放在config/application.rb、config/environment.rb和config.ru中。我用我的应用程序名替换了“Whatever”。

Rails 3似乎不能以gem的形式使用这个插件。也许机架应用程序无法从gems加载?我将其作为插件安装,并将配置语法更改为:

config.middleware.use:::ExceptionNotifier“

而不是


config.middleware.use ExceptionNotifier

这需要一些工作,但我得到了使用Rails 3.0.0的异常通知程序:

1-
rails插件安装http://github.com/sickill/exception_notification.git

(如果您不想使用此fork,只需手动应用于原始Rails插件:它只有3行。)它修复了“未定义的方法控制器\u name错误”

2-在application.rb中:

config.middleware.use "::ExceptionNotifier" , :email_prefix => "[Whatever] ",
                           :sender_address => %{"notifier" <notifier@example.com>},
                           :exception_recipients => %w{whoever@example.com} 
config.middleware.use:::ExceptionNotifier“,:email\u prefix=>“[任何]”,
:发送者\地址=>%{“通知者”},
:例外情况\u收件人=>%w{whoever@example.com} 
3-申请。(更新:此链接似乎已断开)它修复了所记录的
未初始化常量ActiveRecord::RecordNotFound
错误


就是这样。

事实上,现在要容易得多。在
Gemfile
中,您需要编写:

gem "exception_notification", :git => "http://github.com/rails/exception_notification.git", :require => 'exception_notifier'
所有的问题都应该解决。
:require
选项至关重要(我想是因为名称不同,您必须明确指定)。
我想前面提到的所有其他补丁都已经合并了。

好了,我现在可以使用了:

# Gemfile
gem "exception_notification", :git => "git://github.com/rails/exception_notification", :require => 'exception_notifier'

# application.rb, inside the config block
config.middleware.use ::ExceptionNotifier,
  :email_prefix => "ApplicationName-Errors: ",
  :sender_address => %w{office@application.com},
  :exception_recipients => %w{office@application.com}

我能够让它在production.rb中使用以下内容:

config.after_initialize do
 config.middleware.use ExceptionNotifier,
      :email_prefix => "[Whatever] ",
      :sender_address => %{"notifier" <notifier@example.com>},
      :exception_recipients => %w{exceptions@example.com}
end
config.after\u初始化do
config.middleware.use ExceptionNotifier,
:email_prefix=>“[任何]”,
:发送者\地址=>%{“通知者”},
:例外情况\u收件人=>%w{exceptions@example.com}
结束

我刚才遇到了同样的问题,并通过以下方式解决:

Gemfile

source 'http://rubygems.org'
gem 'exception_notification_rails3', :require => 'exception_notifier'
application.rb

config.middleware.use ExceptionNotifier,
  :email_prefix => "[some prefix] ",
  :sender_address => %{"Notifier" <notify@domain.com>},
  :exception_recipients => %w{recipient@domain.com}
Rails.application.config.middleware.use ExceptionNotifier,
  :email_prefix => "[Whatever] ",
  :sender_address => %{"notifier" <notifier@example.com>},
  :exception_recipients => %w{exceptions@example.com}  
config.middleware.use ExceptionNotifier,
:email_prefix=>“[某些前缀]”,
:发送者\地址=>%{“通知者”},
:例外情况\u收件人=>%w{recipient@domain.com}
我正在将Rails2.3项目重构为3.0,所以我还没有在新安装中尝试过

编辑:

实际上,将ExceptionNotifier初始化放在config/initializers/中的一个单独的初始化器文件中,而不是application.rb,可能会更好(或“更正确”)

config/initializers/exception_notifier.rb

MyApp::Application.config.middleware.use ExceptionNotifier,
  :email_prefix => "[some prefix] ",
  :sender_address => %{"Notifier" <notify@domain.com>},
  :exception_recipients => %w{recipient@domain.com}
MyApp::Application.config.middleware.use ExceptionNotifier,
:email_prefix=>“[某些前缀]”,
:发送者\地址=>%{“通知者”},
:例外情况\u收件人=>%w{recipient@domain.com}

以前的所有答案都已过时,您现在只需将其添加到您的文件中即可:

gem 'exception_notification', :require => 'exception_notifier'
并编辑production.rb配置文件,如自述文件所示:

config.middleware.use ExceptionNotifier,
  :email_prefix => "[Exception] ",
  :sender_address => %{"Exception Notifier" <support@example.com>},
  :exception_recipients => %w{you@me.com}
config.middleware.use ExceptionNotifier,
:email_prefix=>“[例外]”,
:发件人地址=>%{“异常通知程序”},
:例外情况\u收件人=>%w{you@me.com}

我使用的是rails 3.0.4,问题与上面相同。对我来说唯一有效的解决方案是将Rails3的异常通知v1.2作为插件安装(确保使用正确的分支/版本)

rails plugin install https://github.com/railsware/exception_notification.git
并在production.rb中使用每个人都提到的代码:

config.middleware.use ExceptionNotifier,
  :email_prefix => "[some prefix] ",
  :sender_address => %{"Notifier" <notify@domain.com>},
  :exception_recipients => %w{recipient@domain.com}
config.middleware.use ExceptionNotifier,
:email_prefix=>“[某些前缀]”,
:发送者\地址=>%{“通知者”},
:例外情况\u收件人=>%w{recipient@domain.com}
作为gem,它肯定不适用于我,自述文件确实说了“Rails的异常通知插件”,并且没有提到将其安装为gem


Harry使用Rails 3.0.3这对我来说很有用:

gem "exception_notification", :git => "https://github.com/sickill/exception_notification.git", :require => 'exception_notifier'
:git part已导入,因为它是一个修补版本,用于绕过“undefined method controller_name error”,并且:require需要正确的库

然后在我的production.rb环境文件中,我只有这个(来自手册)

config.middleware.use ExceptionNotifier,
:email_prefix=>“[MyApp]”,
:发送者\地址=>%{“通知者”},
:例外情况\u收件人=>%w{email@example.com}
似乎有很多不同的方法可以让它发挥作用,但这是我的方法


干杯

github的官方回购现在是:

在档案中

gem "exception_notification", :require => 'exception_notifier', :git => "https://github.com/smartinez87/exception_notification.git"
在config\initializers\exception\u notification.rb中

config.middleware.use ExceptionNotifier,
  :email_prefix => "[some prefix] ",
  :sender_address => %{"Notifier" <notify@domain.com>},
  :exception_recipients => %w{recipient@domain.com}
Rails.application.config.middleware.use ExceptionNotifier,
  :email_prefix => "[Whatever] ",
  :sender_address => %{"notifier" <notifier@example.com>},
  :exception_recipients => %w{exceptions@example.com}  
Rails.application.config.middleware.use ExceptionNotifier,
:email_prefix=>“[任何]”,
:发送者\地址=>%{“通知者”},
:例外情况\u收件人=>%w{exceptions@example.com}  

最新版本的官方gem与Rails 3配合使用,您可以在此处找到它:

下一个gem版本将不需要
:require=>“异常通知程序”
选项。

这个gem已经针对Rails3.x进行了更新,我刚刚在3.0.7上进行了测试,安装更加简单

档案:

gem 'exception_notification'
gem 'exception_notification'
初始值设定项:

Rails.application.config.middleware.use ExceptionNotifier,
  :email_prefix => "[Whatever] ",
  :sender_address => %{"notifier" <notifier@example.com>},
  :exception_recipients => %w{exceptions@example.com}
Rails.application.config.middleware.use ExceptionNotifier,
:email_prefix=>“[任何]”,
:发送者\地址=>%{“通知者”},
:例外情况\u收件人=>%w{exceptions@example.com}
保持简单愚蠢

gemfile中

gem 'exception_notification', :require => 'exception_notifier'
在application.rb文件中

config.middleware.use ExceptionNotifier,
:email_prefix=>“[错误]”,
:发件人地址=>%{“异常通知程序”},
:异常\u收件人=>%w{Dummy_email@example.com}

您的任务已完成..:*

如果您正在使用::render_500从异常中营救,以处理显示500个模板/页面的问题,则它不再发送仅包含此内容的电子邮件

    config.middleware.use ExceptionNotifier,
  :email_prefix => "[some prefix] ",
  :sender_address => %{"Notifier" <notify@domain.com>},
  :exception_recipients => %w{recipient@domain.com}
因此,将配置内容放入您的环境(production.rb)和异常处理中
gem 'exception_notification'
Whatever::Application.config.middleware.use ExceptionNotifier,
  :email_prefix => "[Whatever] ",
  :sender_address => %{"notifier" <notifier@example.com>},
  :exception_recipients => %w{exceptions@example.com}
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
 :email => {
   :email_prefix => "[Whatever] ",
   :sender_address => %{"notifier" <notifier@example.com>},
   :exception_recipients => %w{exceptions@example.com}
 }
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
  :email => {
    :email_prefix => "[Whatever] ",
    :sender_address => %{"notifier" <notifier@example.com>},
    :exception_recipients => %w{exceptions@example.com}
  }