{"id":8152,"date":"2019-12-08T22:21:57","date_gmt":"2019-12-08T13:21:57","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=8152"},"modified":"2023-05-27T22:52:15","modified_gmt":"2023-05-27T13:52:15","slug":"%e3%80%90ruby-on-rails%e3%80%91%e3%83%a2%e3%83%87%e3%83%ab%e3%82%92%e5%85%b1%e9%80%9a%e5%8c%96%e3%81%99%e3%82%8b%e3%80%82","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=8152","title":{"rendered":"\u3010Ruby on Rails\u3011\u30e2\u30c7\u30eb\u3092\u5171\u901a\u5316\u3059\u308b\u3002"},"content":{"rendered":"<p>\u30d3\u30b8\u30cd\u30b9\u30ed\u30b8\u30c3\u30af\u3092\u8a18\u8ff0\u3059\u308b\u30e2\u30c7\u30eb\u306f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u8907\u96d1\u306b\u306a\u308a\u3084\u3059\u3044\u3067\u3059\u3002\u4e0b\u8a18\u306e\u65b9\u6cd5\u3067\u30e2\u30c7\u30eb\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u5171\u901a\u5316\u3057\u3066\u7c21\u7d20\u5316\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u5171\u901a\u51e6\u7406\u3092\u30e2\u30b8\u30e5\u30fc\u30eb\u5316\u3057\u30e2\u30c7\u30eb\u306bMix-in\u3059\u308b\u3002<\/li>\n<li>\u30af\u30e9\u30b9\u306e\u7d99\u627f\u3092\u884c\u3046\u3002<\/li>\n<li>\u5171\u901a\u51e6\u7406\u3092\u62c5\u3046\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u5225\u306b\u4f5c\u3063\u3066\u9023\u643a\u3055\u305b\u308b\u3002<\/li>\n<\/ul>\n<h2>\u5171\u901a\u51e6\u7406\u3092\u30e2\u30b8\u30e5\u30fc\u30eb\u5316\u3057\u30e2\u30c7\u30eb\u306bMix-in\u3059\u308b\u3002<\/h2>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">module \u30e2\u30b8\u30e5\u30fc\u30eb\u540d\r\n  extend ActiveSupport::Concern\r\n\r\n  #\u5171\u901a\u30e1\u30bd\u30c3\u30c9\u7fa4\r\nend<\/pre>\n<h3>extend ActiveSupport::Concern<\/h3>\n<p>Rails\u3067Mix-in\u306e\u305f\u3081\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u8a18\u8ff0\u3059\u308b\u6642\u306b\u3088\u304f\u4f7f\u308f\u308c\u308b\u8a18\u8ff0\u306b\u306a\u308a\u307e\u3059\u3002\u666e\u901a\u306eRuby\u30af\u30e9\u30b9\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u5316\u306b\u6bd4\u3079\u3066\u66f8\u304d\u3084\u3059\u304f\u3057\u3066\u304f\u308c\u307e\u3059\u3002\u3053\u306e\u30b3\u30fc\u30c9\u306f<span style=\"color: #ff0000;\"><strong>\u300capp\/models\/concerns\u300d<\/strong><\/span>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u914d\u7f6e\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30af\u30e9\u30b9\u306e\u7d99\u627f<\/h2>\n<h3>STI(\u5358\u4e00\u30c6\u30fc\u30d6\u30eb\u7d99\u627f\uff09\u306b\u3088\u308a\u5171\u901a\u6a5f\u80fd\u3092\u57fa\u5e95\u30af\u30e9\u30b9\u306b\u6301\u305f\u305b\u308b\u3002<\/h3>\n<p>Rails\u3067\u306f\u7d99\u627f\u95a2\u4fc2\u306b\u3042\u308b\u4e00\u9023\u306e\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u30921\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u7d10\u4ed8\u3051\u307e\u3059\u3002\u3053\u308c\u3092STI\u3068\u547c\u3073\u307e\u3059\u3002\u975e\u5e38\u306b\u4fbf\u5229\u3067\u3059\u304c\u4e0b\u8a18\u306e\u30c7\u30e1\u30ea\u30c3\u30c8\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<h4>STI\u306e\u30c7\u30e1\u30ea\u30c3\u30c8<\/h4>\n<ul>\n<li>\u30c7\u30fc\u30bf\u304c\u4e00\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u96c6\u4e2d\u3059\u308b\u306e\u3067\u51e6\u7406\u901f\u5ea6\u4f4e\u4e0b\u306e\u539f\u56e0\u3068\u306a\u308b\u5834\u5408\u304c\u3042\u308b\u3002<\/li>\n<li>\u30af\u30e9\u30b9\u540d\u5909\u66f4\u306e\u305f\u3073\u306bDB\u5185\u306etype\u30ab\u30e9\u30e0\u3092\u5909\u66f4\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<\/li>\n<li>\u30af\u30e9\u30b9\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u5dee\u7570\u304c\u5927\u304d\u3044\u5834\u5408\u306fDB\u5229\u7528\u52b9\u7387\u304c\u60aa\u304f\u306a\u308b\u3002<\/li>\n<\/ul>\n<h4>STI\u3092\u4f7f\u3063\u305f\u65b9\u304c\u826f\u3044\u5834\u9762<\/h4>\n<ul>\n<li>\u30af\u30e9\u30b9\u540c\u58eb\u306e\u95a2\u4fc2\u304c\u300cA\u306fB\u300d\u306e1\u7a2e\u985e\u3067\u3042\u308b\u5834\u5408<\/li>\n<li>STI\u3068\u3057\u3066\u5171\u6709\u3059\u308b\u5404\u30af\u30e9\u30b9\u9593\u3067\u30ab\u30e9\u30e0\u306b\u5927\u304d\u306a\u5dee\u7570\u304c\u306a\u3044\u5834\u5408<\/li>\n<li>\u307e\u3068\u3081\u308b\u30af\u30e9\u30b9\u540c\u58eb\u304c\u4f3c\u3066\u3044\u308b\u5834\u5408<\/li>\n<\/ul>\n<h3>ApplicationRecord\u306b\u5171\u901a\u51e6\u7406\u3092\u8a18\u8ff0\u3059\u308b\u3002<\/h3>\n<p>Rails\u5185\u306e\u5168\u3066\u306e\u5171\u901a\u306e\u632f\u308b\u821e\u3044\u3092ApplicationRecord\u306b\u8a18\u8ff0\u3067\u304d\u307e\u3059\u3002\uff08\u5168\u3066\u306e\u30af\u30e9\u30b9\u306b\u304a\u3044\u3066\u5171\u901a\u306e\u305f\u3081\uff09<\/p>\n<h4>\u5229\u7528\u4f8b<\/h4>\n<ul>\n<li>DB\u3078\u306e\u64cd\u4f5c\u3092\u5e38\u306b\u8a18\u9332\u3059r\u3002<\/li>\n<li>ActiveRecord::Base\u306e\u52d5\u4f5c\u3092\u4e0a\u66f8\u304d\u3059\u308b\u3002<\/li>\n<li>\u30e2\u30c7\u30eb\u5168\u4f53\u3067\u4f7f\u3048\u308bDSL\u3092\u5b9a\u7fa9\u3059\u308b\u3002<\/li>\n<\/ul>\n<p><span style=\"color: #ff0000;\"><strong>\u5168\u3066\u306e\u30e2\u30c7\u30eb\u306b\u304a\u3044\u3066\u5171\u901a\u306e\u632f\u308b\u821e\u3044\u306e\u307f<\/strong><\/span>\u3053\u3053\u306b\u8a18\u8ff0\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002\u3067\u306a\u3051\u308c\u3070\u610f\u56f3\u3057\u306a\u3044\u52d5\u4f5c\u3092\u3057\u3066\u3057\u307e\u3044\u304b\u306d\u307e\u305b\u3093\u3002<\/p>\n<h3>\u4e2d\u9593\u7684\u306a\u30af\u30e9\u30b9\u3092\u4f5c\u3063\u3066\u4e00\u90e8\u306e\u30af\u30e9\u30b9\u7fa4\u3060\u3051\u5171\u901a\u5316\u3059\u308b\u3002<\/h3>\n<p>ApplicationRecord\u3068\u5b9f\u969b\u306e\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u306e\u4e2d\u9593\u7684\u306a\u30af\u30e9\u30b9\u3092\u4f5c\u308c\u3070\u4e00\u90e8\u306e\u30af\u30e9\u30b9\u306b\u3060\u3051\u7d99\u627f\u3055\u305b\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">class \u4e00\u90e8\u3060\u3051\u5171\u901a\u5316\u3059\u308b\u30af\u30e9\u30b9 &lt; ApplicationRecord\r\n  self.abstract_class = true\r\n  #\u5171\u901a\u51e6\u7406\r\nend<\/pre>\n<p>\u305d\u306e\u969b\u306f\u3001\u7d99\u627f\u5c02\u7528\u30af\u30e9\u30b9(\u62bd\u8c61\u30af\u30e9\u30b9)\u3068\u3057\u3066<span style=\"color: #ff0000;\"><strong>self.abstract_class = true<\/strong><\/span>\u3068\u8a18\u8ff0\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u30d3\u30b8\u30cd\u30b9\u30ed\u30b8\u30c3\u30af\u3092\u8a18\u8ff0\u3059\u308b\u30e2\u30c7\u30eb\u306f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u8907\u96d1\u306b\u306a\u308a\u3084\u3059\u3044\u3067\u3059\u3002\u4e0b\u8a18\u306e\u65b9\u6cd5\u3067\u30e2\u30c7\u30eb\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u5171\u901a\u5316\u3057\u3066\u7c21\u7d20\u5316\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 \u5171\u901a\u51e6\u7406\u3092\u30e2\u30b8\u30e5\u30fc\u30eb\u5316\u3057\u30e2\u30c7\u30eb\u306bMix-in\u3059\u308b\u3002 \u30af\u30e9\u30b9\u306e\u7d99\u627f\u3092\u884c\u3046\u3002 \u5171\u901a [&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\/8152"}],"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=8152"}],"version-history":[{"count":8,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/8152\/revisions"}],"predecessor-version":[{"id":20523,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/8152\/revisions\/20523"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8152"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}