{"id":4083,"date":"2014-03-17T14:07:18","date_gmt":"2014-03-17T05:07:18","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=4083"},"modified":"2018-11-14T16:33:51","modified_gmt":"2018-11-14T07:33:51","slug":"rails-4-1-0-%e3%81%a7%e8%bf%bd%e5%8a%a0%e3%81%95%e3%82%8c%e3%81%9f-moduleconcerning-%e3%81%a8%e9%96%a2%e5%bf%83%e4%ba%8b%e3%81%ae%e5%88%86%e9%9b%a2","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2014\/03\/17\/rails-4-1-0-%e3%81%a7%e8%bf%bd%e5%8a%a0%e3%81%95%e3%82%8c%e3%81%9f-moduleconcerning-%e3%81%a8%e9%96%a2%e5%bf%83%e4%ba%8b%e3%81%ae%e5%88%86%e9%9b%a2\/","title":{"rendered":"Rails 4.1.0 \u3067\u8ffd\u52a0\u3055\u308c\u305f Module#concerning \u3068\u95a2\u5fc3\u4e8b\u306e\u5206\u96e2"},"content":{"rendered":"

\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n

Rails 4.1.0 \u3067 Module#concerning \u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n

 <\/p>\n

Module#concerning \u3068\u306f<\/h2>\n

Rails 4.0 \u3067 concerns \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u8ffd\u52a0\u3055\u308c\u305f\u3053\u3068\u3092\u899a\u3048\u3066\u3044\u308b\u3067\u3057\u3087\u3046\u304b\u3002\uff08see \u300c2.4. concerns \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5c0e\u5165<\/a>\u300d\uff09<\/p>\n

concerns \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b Mixin \u7528\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u7f6e\u3044\u3066\u3001\u305d\u308c\u3092\u30e2\u30c7\u30eb\u306a\u308a\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306a\u308a\u3067 include \u3059\u308b\u3001\u3068\u3044\u3046\u4f7f\u3044\u65b9\u3092\u3059\u308b\u3082\u306e\u3067\u3059\u304c\u3001Module#concerning \u3092\u7528\u3044\u308b\u3068\u3001\u308f\u3056\u308f\u3056 concerns \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u305b\u305a\u306b\u3001\u30e2\u30c7\u30eb\u30af\u30e9\u30b9\u306e\u4e2d\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

\u30b3\u30fc\u30c9\u3067\u8868\u3059\u3068\u3001Rails 4.0 \u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n

# app\/models\/article.rb\r\nclass Article < ActiveRecord::Base\r\n  include Tagging\r\nend\r\n\r\n# app\/models\/concerns\/tagging.rb\r\nmodule Tagging\r\n  ...\r\nend<\/pre>\n

\u305d\u308c\u304c Rails 4.1.0 \u3067\u8ffd\u52a0\u3055\u308c\u308b Module#concerning \u3092\u4f7f\u3046\u3068\u3001\u6b21\u306e\u3088\u3046\u306b\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

# app\/models\/article.rb\r\nclass Article < ActiveRecord::Base\r\n  concerning :Tagging do\r\n    ...\r\n  end\r\nend<\/pre>\n

\u8907\u6570\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u5206\u6563\u305b\u305a\u306b\u30b9\u30c3\u30ad\u30ea\u8a18\u8ff0\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\uff01\u30fb\u30fb\u30fb\u306e\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n

\u5c11\u3057\u7d4c\u7def\u3092\u632f\u308a\u8fd4\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n

 <\/p>\n

\u300cFat Controller\u300d\u304b\u3089\u300cSkinny Controller, Fat Model\u300d\u3078<\/h2>\n

\u30d3\u30b8\u30cd\u30b9\u30ed\u30b8\u30c3\u30af\u306b\u95a2\u3059\u308b\u51e6\u7406\u306a\u3069\u3001\u672c\u6765\u306e\u5f79\u5272\u3092\u8d85\u3048\u305f\u30b3\u30fc\u30c9\u3067\u80a5\u5927\u5316\u3057\u305f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306e\u3053\u3068\u3092\u300cFat Controller\u300d\u3068\u547c\u3076\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u300cFat Controller\u300d\u306b\u306f\u30b3\u30fc\u30c9\u306e\u898b\u901a\u3057\u304c\u60aa\u304f\u3001\u30c6\u30b9\u30c8\u3082\u3057\u3065\u3089\u3044\u3068\u3044\u3046\u554f\u984c\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n

\u300cFat Controller\u300d\u306b\u306a\u3089\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u5f79\u5272\u3092\u8003\u3048\u305f\u4e0a\u3067\u30b3\u30fc\u30c9\u3092\u5b9f\u88c5\u3059\u308b\u5834\u6240\u3092\u6c7a\u3081\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u4f8b\u3048\u3070\u30d3\u30b8\u30cd\u30b9\u30ed\u30b8\u30c3\u30af\u3067\u3042\u308c\u3070\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3067\u306f\u306a\u304f\u30b5\u30fc\u30d3\u30b9\u5c64\u306b\u8a18\u8ff0\u3059\u308b\u306a\u3069\u3067\u3059\u3002<\/p>\n

\u3068\u3053\u308d\u304c Rails \u3067\u306f\u5c11\u3057\u56f0\u3063\u305f\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u308c\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u30b5\u30fc\u30d3\u30b9\u5c64\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u30e2\u30c7\u30eb\u306f app\/models\/\u3001View \u306a\u3089 app\/views\/\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306a\u3089 app\/controllers\/ \u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u30b5\u30fc\u30d3\u30b9\u5c64\u3092\u7f6e\u304f\u305f\u3081\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n

\u305d\u308c\u3067\u3069\u3046\u306a\u3063\u305f\u304b\u3068\u3044\u3046\u3068\u3001lib\/ \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30b5\u30fc\u30d3\u30b9\u5c64\u3092\u4f5c\u3063\u3066\u307f\u305f\u308a\u3001app\/services \u306e\u3088\u3046\u306a\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u3063\u3066\u307f\u305f\u308a\u3001\u3082\u3057\u304f\u306f Fat Controller \u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u308a\u3001\u306f\u305f\u307e\u305f View \u306b\u5927\u91cf\u306e\u30ed\u30b8\u30c3\u30af\u3092\u66f8\u3044\u3066\u3057\u307e\u3063\u305f\u308a\u3001\u4eba\u306b\u3088\u3063\u3066\u30d0\u30e9\u30d0\u30e9\u306a\u5bfe\u5fdc\u304c\u306a\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n

\u305d\u3093\u306a\u72b6\u6cc1\u306e\u4e2d\u3067\u300cSkinny Controller, Fat Model<\/a>\u300d\u3068\u8a00\u308f\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002View \u3084\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306b\u672c\u6765\u306e\u5f79\u5272\u3068\u306f\u9055\u3046\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u306e\u3067\u306f\u306a\u304f\u30e2\u30c7\u30eb\u306b\u30b3\u30fc\u30c9\u3092\u5bc4\u305b\u307e\u3057\u3087\u3046\u3001\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n

 <\/p>\n

Fat Model \u304b\u3089\u95a2\u5fc3\u4e8b\u3092\u5206\u96e2\u3059\u308b<\/h2>\n

\u300cSkinny Controller, Fat Model\u300d\u3068\u3044\u3046\u6307\u91dd\u306b\u3088\u3063\u3066\u30e2\u30c7\u30eb\u306b\u30b3\u30fc\u30c9\u304c\u96c6\u307e\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n

Fat Model \u306b\u306a\u3063\u305f\u3053\u3068\u3067\u3001\u4eca\u5ea6\u306f\u30e2\u30c7\u30eb\u306e\u898b\u901a\u3057\u304c\u60aa\u304f\u306a\u308a\u307e\u3057\u305f\u3002\u8272\u3005\u306a\u30b3\u30fc\u30c9\u3092\u30e2\u30c7\u30eb\u306b\u5bc4\u305b\u3066\u3044\u3063\u305f\u306e\u3067\u3001\u30e2\u30c7\u30eb\u306e\u898b\u901a\u3057\u304c\u60aa\u304f\u306a\u308b\u3053\u3068\u306f\u5f53\u305f\u308a\u524d\u3067\u306f\u3042\u308a\u307e\u3059\u3002<\/p>\n

\u305d\u3053\u3067 Rails 4.0 \u3067\u306f app\/models\/concerns \u3084 app\/controllers\/concerns \u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u7528\u610f\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002Fat Model \u3068\u306f\u8a00\u3063\u3066\u3082\u3001\u3042\u308b\u7a0b\u5ea6\u72ec\u7acb\u3057\u305f\u6a5f\u80fd\u3084\u8907\u6570\u30e2\u30c7\u30eb\u3067\u5171\u901a\u3059\u308b\u30b3\u30fc\u30c9\u306f\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u5206\u96e2\u3057\u3066 concerns \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u304a\u304d\u307e\u3057\u3087\u3046\u3001\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n

 <\/p>\n

\u305d\u3057\u3066 Module#concerning<\/h2>\n

\u305d\u3057\u3066 Rails 4.1.0 \u3067\u306f\u5192\u982d\u3067\u7d39\u4ecb\u3057\u305f Module#concerning \u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n

\u3053\u308c\u306f\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u5206\u5272\u3057\u305f\u30b3\u30fc\u30c9\u3092 app\/models\/concerns \u3084 app\/controllers\/concerns \u306b\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u4fdd\u5b58\u305b\u305a\u306b\u3001\u30e2\u30c7\u30eb\u3084\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u5185\u306b\u305d\u306e\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n

\u300c\u306f\u3066\u3001Fat Model \u306b\u623b\u308b\u306e\u3067\u306f\uff1f\u300d\u3068\u3044\u3046\u7591\u554f\u304c\u6cb8\u3044\u3066\u304d\u307e\u3059\u3002<\/p>\n

\u4eca\u73fe\u5728\u3001Module#concerning \u306e\u5177\u4f53\u7684\u306a\u6d3b\u7528\u4f8b\u306f\u601d\u3044\u3064\u3044\u3066\u3044\u307e\u305b\u3093\u3002\u300c\u3053\u306e\u5834\u5408\u306f concerns \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308a\u307e\u3057\u3087\u3046\u3002\u3053\u3046\u3044\u3046\u5834\u5408\u306f Module#concerning \u3092\u4f7f\u3044\u307e\u3057\u3087\u3046\u3002\u300d\u3068\u8a00\u3048\u305f\u3089\u826f\u3044\u306e\u3067\u3059\u304c\u30fb\u30fb\u30fb\u3002<\/p>\n

\u5c11\u306a\u304f\u3068\u3082\u300c\u4eca\u5f8c\u306f concerns \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308b\u306e\u3067\u306f\u306a\u304f Module#concerning \u3092\u4f7f\u3044\u307e\u3057\u3087\u3046\u3002\u300d\u3068\u5358\u7d14\u306b\u6271\u3063\u3066\u826f\u3044\u3082\u306e\u3067\u306f\u306a\u304f\u3001\u5fae\u5999\u306a\u30d0\u30e9\u30f3\u30b9\u611f\u899a\u3092\u8981\u6c42\u3055\u308c\u308b\u65b0\u6a5f\u80fd\u306a\u306e\u3060\u3068\u611f\u3058\u3066\u3044\u307e\u3059\u3002<\/p>\n

 <\/p>\n","protected":false},"excerpt":{"rendered":"

\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n

Rails 4.1.0 \u3067 Module#concerning \u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f\u3002
\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[135,18],"tags":[22,134,24],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/4083"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=4083"}],"version-history":[{"count":13,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/4083\/revisions"}],"predecessor-version":[{"id":4102,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/4083\/revisions\/4102"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=4083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=4083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=4083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}