rails2.3.2 ExceptionNotifier 配置_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > rails2.3.2 ExceptionNotifier 配置

rails2.3.2 ExceptionNotifier 配置

 2012/2/14 10:22:10  t284299773  程序员俱乐部  我要评论(0)
  • 摘要:必须先在项目中要加入pluginexception_notifier(附件就是)然后首先在development.rb文件中加入ActionMailer::Base.delivery_method=:smtpActionMailer::Base.smtp_settings={:address=>"smtp.a-it.jp",:domain=>"smtp.a-it.jp",:port=>25,:authentication=>:login,:user_name=>
  • 标签:rails 配置 not

必须先在项目中要加入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

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

  • exception_notification.rar (9.2 KB)
  • 下载次数: 0
发表评论
用户名: 匿名