免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2907 | 回复: 1
打印 上一主题 下一主题

rails2.3.2 ExceptionNotifier 配置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-02-13 14:51 |只看该作者 |倒序浏览
rails2.3.2 ExceptionNotifier 配置









必须先在项目中要加入plugin




然后

首先在development.rb文件中加入

Ruby代码
  1. ActionMailer::Base.delivery_method = :smtp  
  2. ActionMailer::Base.smtp_settings = {   
  3.     :address => "smtp.a-it.jp",   
  4.     :domain => "smtp.a-it.jp",   
  5.     :port => 25,   
  6.     :authentication => :login,   
  7.     :user_name => "rails",   
  8.     :password => "rails",   
  9. }  

  10. ActionMailer::Base.delivery_method = :smtp
  11. ActionMailer::Base.smtp_settings = {
  12.     :address => "smtp.a-it.jp",
  13.     :domain => "smtp.a-it.jp",
  14.     :port => 25,
  15.     :authentication => :login,
  16.     :user_name => "rails",
  17.     :password => "rails",
  18. } 然后在environment.rb中加入
复制代码
Ruby代码
  1. ActionView::Base.field_error_proc = Proc.new {|html_tag, instance|   
  2. %(<span class="field-with-errors">#{html_tag}</span>)}   
  3. #ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update( :default => '%Y-%m-%d %H:%M:%S' )   
  4. #邮件发送地址   
  5. ExceptionNotifier.sender_address = %("Application Error<error_sender>)   
  6. #邮件前缀   
  7. ExceptionNotifier.email_prefix = "[email title]"  
  8. #邮件接收者   
  9. ExceptionNotifier.exception_recipients = %w(youremails)  

  10. ActionView::Base.field_error_proc = Proc.new {|html_tag, instance|
  11. %(<span class="field-with-errors">#{html_tag}</span>)}
  12. #ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update( :default => '%Y-%m-%d %H:%M:%S' )
  13. #邮件发送地址
  14. ExceptionNotifier.sender_address = %("Application Error<error_sender>)
  15. #邮件前缀
  16. ExceptionNotifier.email_prefix = "[email title]"
  17. #邮件接收者
  18. ExceptionNotifier.exception_recipients = %w(youremails)  
  19. 再在application_controller.rb中加入
复制代码
Ruby代码
  1. rescue_from Exception do |exception|   
  2.     pp exception   
  3.     case exception   
  4.       when "ActionController::NameError"  
  5.       flash[:error] = exception.message.to_s   
  6.       when "ActiveRecord::RecordNotFound"  
  7.       flash[:error] = exception.message.to_s   
  8.       when "ActionController::UnknownAction"  
  9.       flash[:error] = exception.message.to_s.split(".")[0]  rescue  "No action responded to #{params[:action]}"  
  10.       else  
  11.       return rescue_action_in_public(exception)   
  12.     end  
  13.     redirect_to :controller => 'blog', :action => "list"  
  14.   end  

  15. rescue_from Exception do |exception|
  16.     pp exception
  17.     case exception
  18.       when "ActionController::NameError"
  19.       flash[:error] = exception.message.to_s
  20.       when "ActiveRecord::RecordNotFound"
  21.       flash[:error] = exception.message.to_s
  22.       when "ActionController::UnknownAction"
  23.       flash[:error] = exception.message.to_s.split(".")[0]  rescue  "No action responded to #{params[:action]}"
  24.       else
  25.       return rescue_action_in_public(exception)
  26.     end
  27.     redirect_to :controller => 'blog', :action => "list"
复制代码
end 哈哈,这样就大功告成了!!!

论坛徽章:
0
2 [报告]
发表于 2012-02-13 14:51 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP