{"id":2059,"date":"2018-12-03T14:08:06","date_gmt":"2018-12-03T05:08:06","guid":{"rendered":"http:\/\/www.cotegg.com\/blog\/?p=2059"},"modified":"2018-12-03T18:28:15","modified_gmt":"2018-12-03T09:28:15","slug":"rails-controller%e3%81%a7%e8%a1%a8%e7%a4%ba%e3%81%97%e3%81%a6%e3%82%8b%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%ae%e3%83%91%e3%82%b9%e3%82%92%e5%88%a4%e5%ae%9a%e3%81%97%e3%81%9f%e3%81%84","status":"publish","type":"post","link":"https:\/\/www.cotegg.com\/blog\/?p=2059","title":{"rendered":"[Rails] Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u305f\u3044"},"content":{"rendered":"<p>Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u3066\u3001\u6761\u4ef6\u5206\u5c90\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u307e\u305a\u8a66\u3057\u305f\u306e\u304c\u3053\u3061\u3089\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">current_page?(root_path)<\/pre>\n<p>\u3057\u304b\u3057\u30a8\u30e9\u30fc\u304c\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">NoMethodError: undefined method `current_page?'<\/pre>\n<p>\u8abf\u3079\u3066\u307f\u308b\u3068 current_page? \u306f UrlHelper \u306e\u4e2d\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u3066<br \/>\nUrlHelper \u306f ActionView \u306e\u30d8\u30eb\u30d1\u30fc\u306a\u3093\u3067\u3059\u306d\u3002<\/p>\n<p>\u7121\u7406\u306b\u3067\u3082Controller\u3067 current_page? \u3092\u4f7f\u3044\u305f\u3044\u65b9\u306f\u3053\u308c\u3067\u3067\u304d\u308b\u307f\u305f\u3044\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">include ActionView::Helpers::UrlHelper<\/pre>\n<p>&nbsp;<\/p>\n<p>\u3067\u3082\u3001\u308f\u3056\u308f\u3056include\u3059\u308b\u306e\u306f\u306a\u30fc\u3068\u601d\u3063\u3066\u3044\u305f\u3089\u3001<br \/>\ncontroller_path \u3067\u3001controller\u540d\u304c<br \/>\naction_name \u3067\u3001action\u540d\u304c\u53d6\u5f97\u3067\u304d\u308b\u3093\u3067\u3059\u306d\u3002<\/p>\n<p>\u521d\u3081\u3066\u77e5\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u6700\u7d42\u7684\u306b\u306f\u3001\u3053\u308c\u3067\u8868\u793a\u4e2d\u306e\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">if (controller_path == 'hoge' &amp;&amp; action_name == 'fuga')<\/pre>\n<p>&nbsp;<\/p>\n<h3>\u53c2\u8003<\/h3>\n<ul>\n<li><a href=\"https:\/\/qiita.com\/kami_zh\/items\/8b684eefc989d9a56427\">Rails\u3067\u8868\u793a\u4e2d\u306e\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3059\u308b\u65b9\u6cd5<\/a><\/li>\n<li><a href=\"https:\/\/ja.stackoverflow.com\/questions\/19781\/rails%E3%81%AEcontroller%E3%81%AE%E4%B8%AD%E3%81%A7current-page%E3%82%92%E4%BD%BF%E3%81%84%E3%81%9F%E3%81%84\"> rails\u306econtroller\u306e\u4e2d\u3067current_page?\u3092\u4f7f\u3044\u305f\u3044<\/a><\/li>\n<li><a href=\"https:\/\/qiita.com\/toduq\/items\/a9fa48926b060b2d8a5b\">[Rails 4.x] View\u3067\u30a2\u30af\u30b7\u30e7\u30f3\u3054\u3068\u306e\u6761\u4ef6\u5206\u5c90\u3092\u7dba\u9e97\u306b\u66f8\u304f\u5c0f\u6280<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u3066\u3001\u6761\u4ef6\u5206\u5c90\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059 &#8230; <\/p>\n","protected":false},"author":12,"featured_media":2081,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[7],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.13 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Rails] Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u305f\u3044 | \u30b3\u30fc\u30c6\u30c3\u30b0\u306e\u30d0\u30b1\u30c4<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cotegg.com\/blog\/?p=2059\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Rails] Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u305f\u3044 | \u30b3\u30fc\u30c6\u30c3\u30b0\u306e\u30d0\u30b1\u30c4\" \/>\n<meta property=\"og:description\" content=\"Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u3066\u3001\u6761\u4ef6\u5206\u5c90\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059 ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cotegg.com\/blog\/?p=2059\" \/>\n<meta property=\"og:site_name\" content=\"\u30b3\u30fc\u30c6\u30c3\u30b0\u306e\u30d0\u30b1\u30c4\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/COTegg.japan\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-12-03T05:08:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-12-03T09:28:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.cotegg.com\/blog\/wp-content\/uploads\/2018\/12\/rails_logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"saton\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cotegg_japan\" \/>\n<meta name=\"twitter:site\" content=\"@cotegg_japan\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"saton\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.cotegg.com\/blog\/?p=2059#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.cotegg.com\/blog\/?p=2059\"},\"author\":{\"name\":\"saton\",\"@id\":\"https:\/\/www.cotegg.com\/blog\/#\/schema\/person\/93ca0e749253dcd8fc2c4cd8dd5c6a1f\"},\"headline\":\"[Rails] Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u305f\u3044\",\"datePublished\":\"2018-12-03T05:08:06+00:00\",\"dateModified\":\"2018-12-03T09:28:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.cotegg.com\/blog\/?p=2059\"},\"wordCount\":61,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.cotegg.com\/blog\/#organization\"},\"articleSection\":[\"\u6280\u8853\"],\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.cotegg.com\/blog\/?p=2059#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.cotegg.com\/blog\/?p=2059\",\"url\":\"https:\/\/www.cotegg.com\/blog\/?p=2059\",\"name\":\"[Rails] Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u305f\u3044 | \u30b3\u30fc\u30c6\u30c3\u30b0\u306e\u30d0\u30b1\u30c4\",\"isPartOf\":{\"@id\":\"https:\/\/www.cotegg.com\/blog\/#website\"},\"datePublished\":\"2018-12-03T05:08:06+00:00\",\"dateModified\":\"2018-12-03T09:28:15+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.cotegg.com\/blog\/?p=2059#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.cotegg.com\/blog\/?p=2059\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.cotegg.com\/blog\/?p=2059#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.cotegg.com\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Rails] Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u305f\u3044\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.cotegg.com\/blog\/#website\",\"url\":\"https:\/\/www.cotegg.com\/blog\/\",\"name\":\"COTegg\u306e\u30d0\u30b1\u30c4\",\"description\":\"- Bucket of cotegg -\",\"publisher\":{\"@id\":\"https:\/\/www.cotegg.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.cotegg.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"ja\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.cotegg.com\/blog\/#organization\",\"name\":\"COTegg Inc.\",\"url\":\"https:\/\/www.cotegg.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.cotegg.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.cotegg.com\/blog\/wp-content\/uploads\/2015\/07\/logo_color1_yoko-e1436354651882.png\",\"contentUrl\":\"https:\/\/www.cotegg.com\/blog\/wp-content\/uploads\/2015\/07\/logo_color1_yoko-e1436354651882.png\",\"width\":176,\"height\":60,\"caption\":\"COTegg Inc.\"},\"image\":{\"@id\":\"https:\/\/www.cotegg.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/COTegg.japan\/\",\"https:\/\/twitter.com\/cotegg_japan\",\"https:\/\/www.instagram.com\/cotegg_japan\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.cotegg.com\/blog\/#\/schema\/person\/93ca0e749253dcd8fc2c4cd8dd5c6a1f\",\"name\":\"saton\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.cotegg.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6a05e1ac3be4a1ef1348bf2b203cfce7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6a05e1ac3be4a1ef1348bf2b203cfce7?s=96&d=mm&r=g\",\"caption\":\"saton\"},\"url\":\"https:\/\/www.cotegg.com\/blog\/?author=12\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Rails] Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u305f\u3044 | \u30b3\u30fc\u30c6\u30c3\u30b0\u306e\u30d0\u30b1\u30c4","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cotegg.com\/blog\/?p=2059","og_locale":"ja_JP","og_type":"article","og_title":"[Rails] Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u305f\u3044 | \u30b3\u30fc\u30c6\u30c3\u30b0\u306e\u30d0\u30b1\u30c4","og_description":"Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u3066\u3001\u6761\u4ef6\u5206\u5c90\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059 ...","og_url":"https:\/\/www.cotegg.com\/blog\/?p=2059","og_site_name":"\u30b3\u30fc\u30c6\u30c3\u30b0\u306e\u30d0\u30b1\u30c4","article_publisher":"https:\/\/www.facebook.com\/COTegg.japan\/","article_published_time":"2018-12-03T05:08:06+00:00","article_modified_time":"2018-12-03T09:28:15+00:00","og_image":[{"width":300,"height":300,"url":"https:\/\/www.cotegg.com\/blog\/wp-content\/uploads\/2018\/12\/rails_logo.png","type":"image\/png"}],"author":"saton","twitter_card":"summary_large_image","twitter_creator":"@cotegg_japan","twitter_site":"@cotegg_japan","twitter_misc":{"\u57f7\u7b46\u8005":"saton"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.cotegg.com\/blog\/?p=2059#article","isPartOf":{"@id":"https:\/\/www.cotegg.com\/blog\/?p=2059"},"author":{"name":"saton","@id":"https:\/\/www.cotegg.com\/blog\/#\/schema\/person\/93ca0e749253dcd8fc2c4cd8dd5c6a1f"},"headline":"[Rails] Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u305f\u3044","datePublished":"2018-12-03T05:08:06+00:00","dateModified":"2018-12-03T09:28:15+00:00","mainEntityOfPage":{"@id":"https:\/\/www.cotegg.com\/blog\/?p=2059"},"wordCount":61,"commentCount":0,"publisher":{"@id":"https:\/\/www.cotegg.com\/blog\/#organization"},"articleSection":["\u6280\u8853"],"inLanguage":"ja","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.cotegg.com\/blog\/?p=2059#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.cotegg.com\/blog\/?p=2059","url":"https:\/\/www.cotegg.com\/blog\/?p=2059","name":"[Rails] Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u305f\u3044 | \u30b3\u30fc\u30c6\u30c3\u30b0\u306e\u30d0\u30b1\u30c4","isPartOf":{"@id":"https:\/\/www.cotegg.com\/blog\/#website"},"datePublished":"2018-12-03T05:08:06+00:00","dateModified":"2018-12-03T09:28:15+00:00","breadcrumb":{"@id":"https:\/\/www.cotegg.com\/blog\/?p=2059#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cotegg.com\/blog\/?p=2059"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.cotegg.com\/blog\/?p=2059#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.cotegg.com\/blog"},{"@type":"ListItem","position":2,"name":"[Rails] Controller\u3067\u8868\u793a\u3057\u3066\u308b\u30da\u30fc\u30b8\u306e\u30d1\u30b9\u3092\u5224\u5b9a\u3057\u305f\u3044"}]},{"@type":"WebSite","@id":"https:\/\/www.cotegg.com\/blog\/#website","url":"https:\/\/www.cotegg.com\/blog\/","name":"COTegg\u306e\u30d0\u30b1\u30c4","description":"- Bucket of cotegg -","publisher":{"@id":"https:\/\/www.cotegg.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.cotegg.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"ja"},{"@type":"Organization","@id":"https:\/\/www.cotegg.com\/blog\/#organization","name":"COTegg Inc.","url":"https:\/\/www.cotegg.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.cotegg.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.cotegg.com\/blog\/wp-content\/uploads\/2015\/07\/logo_color1_yoko-e1436354651882.png","contentUrl":"https:\/\/www.cotegg.com\/blog\/wp-content\/uploads\/2015\/07\/logo_color1_yoko-e1436354651882.png","width":176,"height":60,"caption":"COTegg Inc."},"image":{"@id":"https:\/\/www.cotegg.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/COTegg.japan\/","https:\/\/twitter.com\/cotegg_japan","https:\/\/www.instagram.com\/cotegg_japan\/"]},{"@type":"Person","@id":"https:\/\/www.cotegg.com\/blog\/#\/schema\/person\/93ca0e749253dcd8fc2c4cd8dd5c6a1f","name":"saton","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.cotegg.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6a05e1ac3be4a1ef1348bf2b203cfce7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6a05e1ac3be4a1ef1348bf2b203cfce7?s=96&d=mm&r=g","caption":"saton"},"url":"https:\/\/www.cotegg.com\/blog\/?author=12"}]}},"_links":{"self":[{"href":"https:\/\/www.cotegg.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2059"}],"collection":[{"href":"https:\/\/www.cotegg.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cotegg.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cotegg.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cotegg.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2059"}],"version-history":[{"count":15,"href":"https:\/\/www.cotegg.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2059\/revisions"}],"predecessor-version":[{"id":2080,"href":"https:\/\/www.cotegg.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2059\/revisions\/2080"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cotegg.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/2081"}],"wp:attachment":[{"href":"https:\/\/www.cotegg.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cotegg.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2059"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cotegg.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}