码迷,mamicode.com
首页 > 其他好文 > 详细

Rails 异常处理

时间:2015-07-06 19:53:39      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:rails   ruby   exception   


### Rails 异常处理 的多种处理方法 


1.  routes match ‘*path‘, via: :all, to: ‘controller#action‘


2.  application.rb 的 exception_app

```ruby
    # application.rb
    config.exceptions_app = ->(env) { ExceptionController.action(:show).call(env) }
    config.action_dispatch.rescue_responses["ActionController::RoutingError"] = :not_found
    config.action_dispatch.rescue_responses["ActionController::BadRequest"] = :bad_request
```

3.  exception_notification config/environments/ 

```ruby
  #异常邮件通知
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => "smtp.163.com",
    :port => 25,
    :domain => "163.com",
    :authentication => :login,
    :user_name => "exceptionnotifier@163.com",
    :password => "1234567zxcvbnm"
  }
  config.middleware.use ExceptionNotifier,
    :email_prefix => "[fgcc程序发生异常]",
    :sender_address => %{"异常通知" <ExceptionNotifier@163.com>},
    :exception_recipients => %w{menxu@funguide.com.cn}
```



4.  Slack & exception_notification

```ruby
    # Gemfile
    # Slack api 封装
    gem ‘slack-notifier‘
    # 异常监控
    gem ‘exception_notification‘

```

版权声明:本文为博主原创文章,未经博主允许不得转载。

Rails 异常处理

标签:rails   ruby   exception   

原文地址:http://blog.csdn.net/menxu_work/article/details/46777637

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!