{"id":7813,"date":"2019-12-02T21:57:43","date_gmt":"2019-12-02T12:57:43","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=7813"},"modified":"2023-05-27T22:56:12","modified_gmt":"2023-05-27T13:56:12","slug":"%e3%80%90ruby-on-rails%e3%80%91%e3%82%a8%e3%83%a9%e3%83%bc%e5%87%a6%e7%90%86%e3%81%ae%e6%a6%82%e8%a6%81","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=7813","title":{"rendered":"\u3010Ruby on Rails\u3011\u30a8\u30e9\u30fc\u51e6\u7406\u306e\u6982\u8981"},"content":{"rendered":"<p>Rails\u306e\u5185\u90e8\u3067\u767a\u751f\u3059\u308b\u30a8\u30e9\u30fc\u306f\u4e0b\u8a18\u306e2\u3064\u306b\u5206\u985e\u3067\u304d\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u56fa\u6709\u306e\u30a8\u30e9\u30fc\uff08\u696d\u52d9\u30a8\u30e9\u30fc\u3001\u30e6\u30fc\u30b6\u30fc\u306b\u8cac\u4efb\u306e\u3042\u308b\u30a8\u30e9\u30fc\uff09<\/li>\n<li>Rails\u56fa\u6709\u306e\u30a8\u30e9\u30fc\uff08\u30b7\u30b9\u30c6\u30e0\u30a8\u30e9\u30fc\u3001\u30b7\u30b9\u30c6\u30e0\u306e\u4e0d\u5177\u5408\u3067\u958b\u767a\u8005\u306b\u8cac\u4efb\u304c\u3042\u308b\u30a8\u30e9\u30fc\uff09<\/li>\n<\/ul>\n<h2>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u56fa\u6709\u306e\u30a8\u30e9\u30fc\u306e\u5834\u5408<\/h2>\n<h3>\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u88c5\u65b9\u91dd<\/h3>\n<p><span style=\"color: #ff0000;\"><strong>\u57fa\u672c\u7684\u306b\u306frescue\u7b49\u306e\u4f8b\u5916\u51e6\u7406\u306f\u884c\u3044\u307e\u305b\u3093\u3002false\u3001true\u7b49\u3067\u5206\u5c90\u51e6\u7406\u3092\u8a18\u8ff0\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/strong><\/span><\/p>\n<h4>rescue_from\u30e1\u30bd\u30c3\u30c9<\/h4>\n<p>\u3042\u307e\u308a\u4f7f\u3046\u3053\u3068\u306f\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u30a2\u30d7\u30ea\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u5185\u3067\u767a\u751f\u3059\u308b\u30a8\u30e9\u30fc\u3067\u624b\u8efd\u306b\u30a8\u30e9\u30fc\u753b\u9762\u3092\u51fa\u3057\u305f\u3044\u5834\u5408\u306f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u308b<span style=\"color: #ff0000;\"><strong>rescue_from\u30e1\u30bd\u30c3\u30c9<\/strong><\/span>\u304c\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<p>\u5177\u4f53\u7684\u306b\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">class \u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\r\n  rescue_from XXXError, with: \u30a8\u30e9\u30fc\u51e6\u7406\u30e1\u30bd\u30c3\u30c9  \r\n\r\n  private\r\n    def \u30a8\u30e9\u30fc\u51e6\u7406\u30e1\u30bd\u30c3\u30c9(error)\r\n      @error = error\r\n      render :custom_error\r\n    end\r\nend<\/pre>\n<h4>rescue_from\u30e1\u30bd\u30c3\u30c9\u306e\u6ce8\u610f\u70b9<\/h4>\n<p>\u975e\u5e38\u306b\u4fbf\u5229\u306a\u30e1\u30bd\u30c3\u30c9\u306a\u306e\u3067\u3059\u304c\u3001config.consider_all_requests_local\u306e\u5024\u306b\u95a2\u308f\u3089\u305a\u5e38\u6642\u767a\u52d5\u3059\u308b\u305f\u3081\u30c7\u30d0\u30c3\u30b0\u6642\u306b\u4e0d\u4fbf\u306b\u306a\u308b\u70b9\u3067\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u30a8\u30e9\u30fc\u8a73\u7d30\u3092\u96a0\u3059\u8a2d\u5b9a\u306b\u3057\u3066\u3057\u307e\u3046\u3068\u30a2\u30d7\u30ea\u56fa\u6709\u306e\u30a8\u30e9\u30fc\u5185\u5bb9\u307e\u3067\u96a0\u853d\u3055\u308c\u3066\u3057\u307e\u3044\u958b\u767a\u901f\u5ea6\u304c\u4f4e\u4e0b\u3057\u3066\u3057\u307e\u3046\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h2>Rails\u56fa\u6709\u306e\u30a8\u30e9\u30fc\u306e\u5834\u5408\uff08\u30b7\u30b9\u30c6\u30e0\u30a8\u30e9\u30fc\uff09<\/h2>\n<h3>\u30d7\u30ed\u30b0\u30e9\u30e0\u5b9f\u88c5\u65b9\u91dd\u306b\u3064\u3044\u3066<\/h3>\n<p>Rails\u306e\u5171\u901a\u51e6\u7406\u304c\u81ea\u52d5\u7684\u306b\u30ed\u30b0\u306b\u51fa\u529b\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u57fa\u672c\u7684\u306b\u306f<span style=\"color: #ff0000;\"><strong>\u4f55\u3082\u3057\u306a\u3044<\/strong><\/span>\u306e\u304c\u6b63\u89e3\u3067\u3059\u3002rescue\u3092\u4f7f\u3063\u3066\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d9a\u884c\u3055\u305b\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<span style=\"color: #ff0000;\"><strong>(Rails\u304c\u81ea\u52d5\u3067rescue\u306e\u51e6\u7406\u3092\u3057\u3066\u304f\u308c\u3066\u3044\u307e\u3059\u3002)<\/strong><\/span>\u305f\u3060\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u4f8b\u5916\u7684\u306a\u30b1\u30fc\u30b9\u3082\u3042\u308b\u306e\u3067\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h4>rescue\u3092\u4f7f\u3044\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d9a\u884c\u3055\u305b\u305f\u65b9\u304c\u826f\u3044\u4f8b\u5916\u7684\u306a\u30b1\u30fc\u30b9<\/h4>\n<ul>\n<li>DB\u306b\u5927\u91cf\u30c7\u30fc\u30bf\u767b\u9332\u3059\u308b\u51e6\u7406\u3067\u9014\u4e2d\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u304b\u3089\u3068\u3044\u3063\u3066\u5168\u4ef6\u767b\u9332\u3092\u30b9\u30c8\u30c3\u30d7\u3055\u305b\u308b\u3053\u3068\u304c\u4ed5\u69d8\u3068\u3057\u3066\u554f\u984c\u304c\u3042\u308b\u30b1\u30fc\u30b9\u306e\u5834\u5408<\/li>\n<\/ul>\n<p>\u306a\u304a\u3001\u3084\u3080\u304a\u3048\u305a<span style=\"color: #ff0000;\"><strong>rescue\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d9a\u884c\u3055\u305b\u308b\u5834\u5408\u306f\u30ed\u30b0\u51fa\u529b\u3084\u901a\u77e5\u306f\u5fc5\u305a\u884c\u3046<\/strong><\/span>\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h4>\u901a\u77e5\u3059\u308b\u305f\u3081\u306e\u4ee3\u8868\u7684\u306aRubyGem<\/h4>\n<ul>\n<li>Bugsnag<\/li>\n<li>Rollbar<\/li>\n<li>Errbit<\/li>\n<\/ul>\n<h3>\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u969b\u306b\u51fa\u3059\u753b\u9762\u306b\u3064\u3044\u3066<\/h3>\n<p>Rails\u306f\u81ea\u52d5\u3067\u30ed\u30b0\u306b\u969c\u5bb3\u5185\u5bb9\u3092\u51fa\u529b\u3057\u3066\u304f\u308c\u307e\u3059\u3057<span style=\"color: #ff0000;\"><strong>\u30a8\u30e9\u30fc\u753b\u9762\u3082\u81ea\u52d5\u3067\u51fa\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/strong><\/span>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067\u3069\u306e\u3088\u3046\u306b\u51e6\u7406\u3092\u3055\u305b\u308b\u304b\u6c7a\u3081\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u4ee5\u4e0b\uff12\u3064\u306e\u3069\u3061\u3089\u304b\u306e\u753b\u9762\u3092\u51fa\u3059\u3068\u3044\u3046\u8a2d\u5b9a\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u30c7\u30d0\u30c3\u30b0\u7528\u753b\u9762<\/li>\n<li>\u672c\u756a\u7528\u30a8\u30e9\u30fc\u753b\u9762<\/li>\n<\/ul>\n<h4>\u3069\u306e\u753b\u9762\u3092\u51fa\u3059\u304b\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb<\/h4>\n<p>config\/environments\/development.rb<\/p>\n<h5>\u8a2d\u5b9a\u5024<\/h5>\n<p>config.consider_all_requests_local<\/p>\n<p>\u3053\u306e\u5024\u304ctrue\u306e\u6642\u306f\u30c7\u30d0\u30c3\u30b0\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u3066\u3001false\u306e\u6642\u306f\u672c\u756a\u7528\u306e\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306ftrue\u306b\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u30c7\u30d0\u30c3\u30b0\u7528\u306e\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u958b\u767a\u3055\u308c\u3066\u3044\u308b\u4e2d\u3067\u4f55\u5ea6\u304b\u76ee\u306b\u3057\u305fRails\u306e\u3042\u308b\u884c\u6570\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u3066\u3044\u307e\u3059\u3068\u3044\u3046\u3088\u3046\u306a\u753b\u9762\u306f\u30c7\u30d0\u30c3\u30b0\u753b\u9762\u306a\u306e\u3067\u3059\u3002\uff09<\/p>\n<h4>\u672c\u756a\u7528\u30a8\u30e9\u30fc\u753b\u9762\u306b\u3064\u3044\u3066<\/h4>\n<p>\u672c\u756a\u7528\u30a8\u30e9\u30fc\u753b\u9762\u306fHTTP\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u3054\u3068\u306b\u7528\u610f\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<table>\n<tbody>\n<tr>\n<th width=\"150\">\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9<\/th>\n<th>\u8aac\u660e<\/th>\n<th>HTML\u306e\u5834\u6240<\/th>\n<\/tr>\n<tr>\n<td>404<\/td>\n<td>\u30e6\u30fc\u30b6\u30fc\u306e\u6c42\u3081\u3066\u3044\u308b\u30ea\u30bd\u30fc\u30b9\u3092\u63d0\u4f9b\u3067\u304d\u306a\u3044\u5834\u5408\u306e\u30a8\u30e9\u30fc\uff08Action\u304c\u306a\u3044\u3001\u30c7\u30fc\u30bf\u304c\u306a\u3044\u7b49\uff09<\/td>\n<td>public\/404.html<\/td>\n<\/tr>\n<tr>\n<td>422<\/td>\n<td><\/td>\n<td>public\/422.html<\/td>\n<\/tr>\n<tr>\n<td>500<\/td>\n<td>\u305d\u306e\u4ed6\u306e\u30b7\u30b9\u30c6\u30e0\u30a8\u30e9\u30fc\u5168\u822c<\/td>\n<td>public\/500.html<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3042\u304f\u307e\u3067\u9759\u7684\u306a\u30da\u30fc\u30b8\u306b\u306a\u308a\u307e\u3059\u3002\u305f\u3060<span style=\"color: #ff0000;\"><strong>\u81ea\u5206\u3067\u597d\u304d\u306a\u3088\u3046\u306a\u30c7\u30b6\u30a4\u30f3\u3092\u3044\u3058\u3063\u305f\u308a\u3059\u308b\u3053\u3068\u306f\u53ef\u80fd<\/strong><\/span>\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Rails\u306e\u5185\u90e8\u3067\u767a\u751f\u3059\u308b\u30a8\u30e9\u30fc\u306f\u4e0b\u8a18\u306e2\u3064\u306b\u5206\u985e\u3067\u304d\u307e\u3059\u3002 \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u56fa\u6709\u306e\u30a8\u30e9\u30fc\uff08\u696d\u52d9\u30a8\u30e9\u30fc\u3001\u30e6\u30fc\u30b6\u30fc\u306b\u8cac\u4efb\u306e\u3042\u308b\u30a8\u30e9\u30fc\uff09 Rails\u56fa\u6709\u306e\u30a8\u30e9\u30fc\uff08\u30b7\u30b9\u30c6\u30e0\u30a8\u30e9\u30fc\u3001\u30b7\u30b9\u30c6\u30e0\u306e\u4e0d\u5177\u5408\u3067\u958b\u767a\u8005\u306b\u8cac\u4efb\u304c\u3042\u308b\u30a8\u30e9\u30fc\uff09  [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[36],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/7813"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7813"}],"version-history":[{"count":15,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/7813\/revisions"}],"predecessor-version":[{"id":20534,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/7813\/revisions\/20534"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7813"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}