rails2.3.2 ExceptionNotifier 配置

必须先在项目中要加入plugin

 

exception_notifier(附件就是)

 

然后

首先在development.rb文件中加入

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
    :address => "smtp.a-it.jp",
    :domain => "smtp.a-it.jp",
    :port => 25,
    :authentication => :login,
    :user_name => "rails",
    :password => "rails",
}

 然后在environment.rb中加入

ActionView::Base.field_error_proc = Proc.new {|html_tag, instance|
%(<span class="field-with-errors">#{html_tag}</span>)}
#ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update( :default => '%Y-%m-%d %H:%M:%S' )
#邮件发送地址
ExceptionNotifier.sender_address = %("Application Error<error_sender>)
#邮件前缀
ExceptionNotifier.email_prefix = "[email title]"
#邮件接收者
ExceptionNotifier.exception_recipients = %w(youremails)
 

再在application_controller.rb中加入

rescue_from Exception do |exception|
    pp exception
    case exception
      when "ActionController::NameError"
      flash[:error] = exception.message.to_s
      when "ActiveRecord::RecordNotFound"
      flash[:error] = exception.message.to_s
      when "ActionController::UnknownAction"
      flash[:error] = exception.message.to_s.split(".")[0]  rescue  "No action responded to #{params[:action]}"
      else
      return rescue_action_in_public(exception)
    end
    redirect_to :controller => 'blog', :action => "list"
  end

 哈哈,这样就大功告成了!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值