{"id":153,"date":"2020-09-15T18:57:30","date_gmt":"2020-09-15T09:57:30","guid":{"rendered":"https:\/\/tech.aoiblog.net\/?p=153"},"modified":"2020-09-19T11:01:04","modified_gmt":"2020-09-19T02:01:04","slug":"9%e6%9c%8815%e6%97%a5%e3%81%ae%e5%ad%a6%e7%bf%92%e5%86%85%e5%ae%b9","status":"publish","type":"post","link":"https:\/\/tech.aoiblog.net\/?p=153","title":{"rendered":"9\u670815\u65e5\u306e\u5b66\u7fd2\u5185\u5bb9"},"content":{"rendered":"\n<p>\u3053\u3093\u3070\u3093\u306f\uff01<br>\u672c\u65e5\u3082\u30c6\u30c3\u30af\u30d6\u30ed\u30b0\u306e\u66f4\u65b0\u7d99\u7d9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"m\">\u672c\u65e5\u306e\u5b66\u7fd2\u5185\u5bb9<\/h2>\n\n\n\n<ul class=\"m\"><li>user_signed_in?\u30e1\u30bd\u30c3\u30c9<\/li><li>unless<\/li><li>except\u30aa\u30d7\u30b7\u30e7\u30f3<\/li><li>maxlength\u30aa\u30d7\u30b7\u30e7\u30f3<\/li><li>current_user\u30e1\u30bd\u30c3\u30c9<\/li><li>includes\u30e1\u30bd\u30c3\u30c9<\/li><li>order\u30e1\u30bd\u30c3\u30c9<\/li><\/ul>\n\n\n\n<h3 class=\"m\">user_signed_in?\u30e1\u30bd\u30c3\u30c9<\/h3>\n\n\n\n<p>Gem\u306edevise\u3092\u5c0e\u5165\u3057\u3066\u3044\u308b\u305f\u3081\u4f7f\u7528\u3067\u304d\u308b\u30e1\u30bd\u30c3\u30c9\u3002\u3000<\/p>\n\n\n\n<p>user_signed_in?\u30e1\u30bd\u30c3\u30c9\u306f\u30e6\u30fc\u30b6\u30fc\u304c\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u308c\u3070true\u3001\u30ed\u30b0\u30a2\u30a6\u30c8 \u72b6\u614b\u3067\u3042\u308c\u3070\u3001false\u3092\u8fd4\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"m\">unless<\/h3>\n\n\n\n<p>if\u3068\u540c\u3058\u304f\u6761\u4ef6\u5f0f\u306e\u8fd4\u308a\u5024\u3067\u6761\u4ef6\u5206\u5c90\u3057\u3066\u51e6\u7406\u3059\u308b\u6587\u6cd5\u3002<\/p>\n\n\n\n<p>if\u306ftrue\u306e\u3068\u304d\u3001unless\u306ffalse\u306e\u3068\u304d\u3001\u51e6\u7406\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"m\">except\u30aa\u30d7\u30b7\u30e7\u30f3<\/h3>\n\n\n\n<p>\u9664\u5916\u3059\u308b\u3068\u3044\u3046\u610f\u5473\u3002<br>except\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u3064\u3051\u305f\u5f8c\u306b\u6307\u5b9a\u3057\u305f\u30a2\u30af\u30b7\u30e7\u30f3\u306f\u51e6\u7406\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<h3 class=\"m\">maxlength\u30aa\u30d7\u30b7\u30e7\u30f3<\/h3>\n\n\n\n<p>input\u30bf\u30b0\u3092\u751f\u6210\u3059\u308b\u30d8\u30eb\u30d1\u30fc\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u6587\u5b57\u306e\u6700\u5927\u306e\u9577\u3055\u3092\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"m\">current_user\u30e1\u30bd\u30c3\u30c9<\/h3>\n\n\n\n<p>current_user\u306f\u73fe\u5728\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u308b\u30e6\u30fc\u30b6\u30fc\u306e\u60c5\u5831\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"m\">includes\u30e1\u30bd\u30c3\u30c9<\/h3>\n\n\n\n<p>\u5f15\u6570\u306b\u6307\u5b9a\u3055\u308c\u305f\u95a2\u9023\u30e2\u30c7\u30eb\u3092\u4e00\u5ea6\u306e\u30a2\u30af\u30bb\u30b9\u3067\u307e\u3068\u3081\u3066\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"code\">\u5177\u4f53\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@posts = Post.includes(:user)<\/code><\/pre>\n\n\n\n<h3 class=\"m\">order\u30e1\u30bd\u30c3\u30c9<\/h3>\n\n\n\n<p>\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u53d6\u5f97\u3057\u3066\u304d\u305f\u8907\u6570\u306e\u30ec\u30b3\u30fc\u30c9\u60c5\u5831\u306e\u4e26\u3073\u66ff\u3048\u3092\u5909\u66f4\u3067\u304d\u308b\u30e1\u30bd\u30c3\u30c9\u3002<\/p>\n\n\n\n<p>\u5177\u4f53\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@posts =  Post.includes(:user).order(\"created_at DESC\")<\/code><\/pre>\n\n\n\n<h2 class=\"m\">\u6700\u5f8c\u306b\uff1a\u672c\u65e5\u3082\u4e00\u6b69\u524d\u9032\u3057\u307e\u3057\u305f\uff01<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"658\" src=\"https:\/\/tech.aoiblog.net\/wp-content\/uploads\/2020\/09\/original_666340675-1024x658.jpg\" alt=\"\" class=\"wp-image-119\" srcset=\"https:\/\/tech.aoiblog.net\/wp-content\/uploads\/2020\/09\/original_666340675-1024x658.jpg 1024w, https:\/\/tech.aoiblog.net\/wp-content\/uploads\/2020\/09\/original_666340675-300x193.jpg 300w, https:\/\/tech.aoiblog.net\/wp-content\/uploads\/2020\/09\/original_666340675-768x493.jpg 768w, https:\/\/tech.aoiblog.net\/wp-content\/uploads\/2020\/09\/original_666340675-1536x987.jpg 1536w, https:\/\/tech.aoiblog.net\/wp-content\/uploads\/2020\/09\/original_666340675-2048x1316.jpg 2048w, https:\/\/tech.aoiblog.net\/wp-content\/uploads\/2020\/09\/original_666340675-940x604.jpg 940w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u6bce\u65e5\u65b0\u3057\u3044\u30e1\u30bd\u30c3\u30c9\u3084\u3089\u6587\u6cd5\u3092\u77e5\u308b\u306e\u304c\u697d\u3057\u304f\u3066\u672c\u5f53\u306b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u53ef\u80fd\u6027\u3063\u3066\u7121\u9650\u5927\u3060\u306a\u3068\u611f\u3058\u308b\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u300c\u65b0\u3057\u3044\u30b5\u30fc\u30d3\u30b9\u3092\u958b\u767a\u3057\u3066\u3044\u308b\u3088\u3046\u306a\u4f1a\u793e\u306b\u53c2\u753b\u3057\u3066\u81ea\u5206\u3082\u958b\u767a\u3057\u305f\u3044\uff01\u300d\u3063\u3066\u5fc3\u304b\u3089\u601d\u3048\u308b\u65e5\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<p><strong>\u4eca\u3053\u3053\u306b\u306a\u3044\u672a\u6765\u306f\u81ea\u5206\u3067\u5275\u308b<\/strong><\/p>\n\n\n\n<p>\u2191\u3053\u308c\u30ea\u30c3\u30c1\u30de\u30f3\u30d7\u30a2\u30a6\u30fc\u30de\u30f3\u3092\u898b\u3066\u597d\u304d\u306b\u306a\u3063\u305f\u8a00\u8449\u3067\u3059\u7b11<\/p>\n\n\n\n<p>\u304a\u308f\u308a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u3070\u3093\u306f\uff01\u672c\u65e5\u3082\u30c6\u30c3\u30af\u30d6\u30ed\u30b0\u306e\u66f4\u65b0\u7d99\u7d9a\u3057\u307e\u3059\u3002 \u672c\u65e5\u306e\u5b66\u7fd2\u5185\u5bb9 user_signed_in?\u30e1\u30bd\u30c3\u30c9 unless except\u30aa\u30d7\u30b7\u30e7\u30f3 maxlength\u30aa\u30d7\u30b7\u30e7\u30f3 current_user\u30e1\u30bd\u30c3\u30c9 includ &#8230; <\/p>\n","protected":false},"author":1,"featured_media":120,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/tech.aoiblog.net\/index.php?rest_route=\/wp\/v2\/posts\/153"}],"collection":[{"href":"https:\/\/tech.aoiblog.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.aoiblog.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.aoiblog.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.aoiblog.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=153"}],"version-history":[{"count":5,"href":"https:\/\/tech.aoiblog.net\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":164,"href":"https:\/\/tech.aoiblog.net\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions\/164"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tech.aoiblog.net\/index.php?rest_route=\/wp\/v2\/media\/120"}],"wp:attachment":[{"href":"https:\/\/tech.aoiblog.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.aoiblog.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.aoiblog.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}