{"id":4609,"date":"2018-06-20T12:46:46","date_gmt":"2018-06-20T03:46:46","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=4609"},"modified":"2023-05-27T23:01:33","modified_gmt":"2023-05-27T14:01:33","slug":"%e3%80%90ruby-on-rails%e3%80%91%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%94%e3%81%a8%e3%81%ab%e3%80%81%e8%aa%ad%e3%81%bf%e8%be%bc%e3%81%be%e3%82%8c%e3%82%8bcss%e3%81%a8javascript%e3%82%92%e5%a4%89%e3%81%88","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=4609","title":{"rendered":"\u3010Ruby on Rails\u3011\u30da\u30fc\u30b8\u3054\u3068\u306b\u3001\u8aad\u307f\u8fbc\u307e\u308c\u308bCSS\u3068JavaScript\u3092\u5909\u3048\u308b\u306b\u306f\uff1f(Rails5\u307e\u3067)"},"content":{"rendered":"<p>Rails\u30a2\u30d7\u30ea\u3067\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u30a2\u30bb\u30c3\u30c8\u306b\u542b\u307e\u308c\u3066\u3044\u308b\uff23\uff33\uff33\u3068JavaScript\u306f\u5168\u3066\u8aad\u307f\u8fbc\u3080\u3088\u3046\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u3066\u3044\u307e\u3059\u3002<\/strong><\/span><\/p>\n<p>\u305f\u3060\u3001\u73fe\u5b9f\u3068\u3057\u3066\u306f<span style=\"color: #ff0000;\"><strong>\u30da\u30fc\u30b8\u3054\u3068\u306b\u8aad\u307f\u8fbc\u307e\u308c\u308b\uff23\uff33\uff33\u3068JavaScript\u3092\u5909\u66f4\u3057\u305f\u3044\u3068\u3044\u3046\u3053\u3068\u304c\u307b\u3068\u3093\u3069<\/strong><\/span>\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u4f5c\u696d\u3092\u884c\u3046\u524d\u306b\u3001\u4e8b\u524d\u306b\u30a2\u30bb\u30c3\u30c8\u306b\u3064\u3044\u3066\u4e0d\u5b89\u306a\u65b9\u306f\u4e0b\u8a18\u306e\u8a18\u4e8b\u3092\u3054\u78ba\u8a8d\u4e0b\u3055\u3044\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"jWySsZ7PTO\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=4602\">\u3010Ruby on Rails\u3011\u30a2\u30bb\u30c3\u30c8(CSS,JavaScript)\u3084\u30de\u30cb\u30d5\u30a7\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u4ed5\u7d44\u307f(Sprockets\u3001Webpacker\uff09<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.code-magagine.com\/?p=4602&#038;embed=true#?secret=jWySsZ7PTO\" data-secret=\"jWySsZ7PTO\" width=\"500\" height=\"282\" title=\"&#8220;\u3010Ruby on Rails\u3011\u30a2\u30bb\u30c3\u30c8(CSS,JavaScript)\u3084\u30de\u30cb\u30d5\u30a7\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u4ed5\u7d44\u307f(Sprockets\u3001Webpacker\uff09&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>\u4e0b\u8a18\u306e\u624b\u9806\u3067\u884c\u3044\u307e\u3059\u3002<\/p>\n<h2>1.\u30de\u30cb\u30d5\u30a7\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u3001require_tree\u306e\u8a18\u8ff0\u3092\u524a\u9664\u3059\u308b\u3002<\/h2>\n<p>\u300crequire_tree\u300d\u306f\u3001\u5168\u3066\u306eCSS\u3001JavaScript\u3092\u8aad\u307f\u8fbc\u3080\u3068\u3044\u3046\u610f\u5473\u306b\u306a\u3063\u3066\u3044\u305f\u306e\u3067\u3001\u500b\u5225\u306b\u5909\u3048\u305f\u3044\u5834\u5408\u306f\u4e0d\u8981\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>css<\/h3>\n<h4>(Rails\u30a2\u30d7\u30ea\u540d)\/app\/assets\/stylesheets\/application.css<\/h4>\n<pre class=\"lang:default decode:true\">\/*\r\n * This is a manifest file that'll be compiled into application.css, which will include all the files\r\n * listed below.\r\n *\r\n * Any CSS and SCSS file within this directory, lib\/assets\/stylesheets, or any plugin's\r\n * vendor\/assets\/stylesheets directory can be referenced here using a relative path.\r\n *\r\n * You're free to add application-wide styles to this file and they'll appear at the bottom of the\r\n * compiled file so the styles you add here take precedence over styles defined in any other CSS\/SCSS\r\n * files in this directory. Styles in this file should be added after the last require_* statement.\r\n * It is generally better to create a new file per style scope.\r\n *\r\n *= require_tree .\u2605\u524a\u9664\u3059\u308b\u3002\r\n *= require_self\r\n *\/<\/pre>\n<h3>JavaScript<\/h3>\n<h4>(Rails\u30a2\u30d7\u30ea\u540d)\/app\/assets\/javascripts\/application.js<\/h4>\n<pre class=\"lang:default decode:true\">\/\/ This is a manifest file that'll be compiled into application.js, which will include all the files\r\n\/\/ listed below.\r\n\/\/\r\n\/\/ Any JavaScript\/Coffee file within this directory, lib\/assets\/javascripts, or any plugin's\r\n\/\/ vendor\/assets\/javascripts directory can be referenced here using a relative path.\r\n\/\/\r\n\/\/ It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the\r\n\/\/ compiled file. JavaScript code in this file should be added after the last require_* statement.\r\n\/\/\r\n\/\/ Read Sprockets README (https:\/\/github.com\/rails\/sprockets#sprockets-directives) for details\r\n\/\/ about supported directives.\r\n\/\/\r\n\/\/= require rails-ujs\r\n\/\/= require activestorage\r\n\/\/= require turbolinks\r\n\/\/= require_tree .\u3000\u2605\u524a\u9664\u3059\u308b\u3002<\/pre>\n<h2>2\uff0e\u30a2\u30bb\u30c3\u30c8\u7528\u306e\u5b9a\u7fa9\u30d5\u30a1\u30a4\u30eb\u306b\u500b\u5225\u3067\u8aad\u307f\u8fbc\u307f\u305f\u3044CSS\u3068JavaScript\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/h2>\n<h3>\u30a2\u30bb\u30c3\u30c8\u7528\u306e\u5b9a\u7fa9\u30d5\u30a1\u30a4\u30eb<\/h3>\n<pre class=\"lang:default decode:true\">(Rails\u30a2\u30d7\u30ea)\/config\/initializers\/assets.rb<\/pre>\n<p>\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u8a2d\u5b9a\u306f\u5168\u3066\u306e\u74b0\u5883\u3067\u8aad\u307f\u8fbc\u307e\u308c\u307e\u3059\u3002\u4e0b\u8a18\u306e\u8a18\u8ff0\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">Rails.application.config.assets.precompile += %w( test.js test.css )<\/pre>\n<p>\u305d\u308c\u305e\u308c\u4e0b\u8a18\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u8aad\u307f\u8fbc\u307f\u5bfe\u8c61\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<table>\n<tbody>\n<tr>\n<th>\u30d5\u30a1\u30a4\u30eb\u306e\u7a2e\u985e<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>\u30b9\u30bf\u30a4\u30eb\u30b7\u30fc\u30c8<\/td>\n<td>(Rails\u30a2\u30d7\u30ea\u540d)\/app\/assets\/stylesheets\/test.scss<\/td>\n<\/tr>\n<tr>\n<td>JavaScript<\/td>\n<td>(Rails\u30a2\u30d7\u30ea\u540d)\/app\/assets\/javascripts\/test.coffee<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>3.\u8aad\u307f\u8fbc\u307e\u305b\u308b\u30a2\u30bb\u30c3\u30c8\u30d5\u30a1\u30a4\u30eb(SCSS\u3001CoffeeScript)\u306e\u5185\u5bb9\u3092\u7de8\u96c6\u3057\u307e\u3059\u3002<\/h2>\n<p>\u305d\u308c\u305e\u308c\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30d5\u30a1\u30a4\u30eb\u5185\u5bb9\u3068\u3057\u3066\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n<h4>css<\/h4>\n<p>(Rails\u30a2\u30d7\u30ea\u540d)\/app\/assets\/stylesheets\/test.scss<\/p>\n<pre class=\"lang:default decode:true\">\/\/ Place all the styles related to the test controller here.\r\n\/\/ They will automatically be included in application.css.\r\n\/\/ You can use Sass (SCSS) here: http:\/\/sass-lang.com\/\r\n\r\nh1{\r\n  color:red;\r\n}<\/pre>\n<h4>JavaScript<\/h4>\n<p>(Rails\u30a2\u30d7\u30ea\u540d)\/app\/assets\/javascripts\/test.coffee<\/p>\n<pre class=\"lang:default decode:true\"># Place all the behaviors and hooks related to the matching controller here.\r\n# All this logic will automatically be available in application.js.\r\n# You can use CoffeeScript in this file: http:\/\/coffeescript.org\/\r\n\r\nalert('Hello World!');<\/pre>\n<h2>4.\u30d3\u30e5\u30fc\u5074\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u3001\u8aad\u307f\u8fbc\u3080\u30a2\u30bb\u30c3\u30c8\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/h2>\n<p>(Rails\u30a2\u30d7\u30ea\u540d)\/app\/views\/test\/index.html.erb<\/p>\n<pre class=\"lang:default decode:true\">&lt;%= stylesheet_link_tag 'test' %&gt;\r\n&lt;%= javascript_include_tag 'test' %&gt;\r\n\r\n&lt;%= @helloworld %&gt;<\/pre>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3001\u5b9a\u7fa9\u30d5\u30a1\u30a4\u30eb\u306b\u5b9a\u7fa9\u3057\u305f\u30b9\u30bf\u30a4\u30eb\u30b7\u30fc\u30c8\u3068\u3001\uff2a\uff33\u3092\u30d3\u30e5\u30fc\u306b\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0a\u3067\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<h2>\u52d5\u4f5c\u691c\u8a3c<\/h2>\n<h3>js\u304c\u9069\u7528\u3055\u308c\u3066\u3044\u308b\u3002<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-4619\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/js\u5b9f\u884c.png\" alt=\"\" width=\"445\" height=\"131\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/js\u5b9f\u884c.png 445w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/js\u5b9f\u884c-300x88.png 300w\" sizes=\"(max-width: 445px) 100vw, 445px\" \/><\/p>\n<h3>css\u304c\u9069\u7528\u3055\u308c\u3066\u3044\u308b\u3002<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-4618\" src=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/css\u9069\u5fdc.png\" alt=\"\" width=\"432\" height=\"159\" srcset=\"http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/css\u9069\u5fdc.png 432w, http:\/\/www.code-magagine.com\/wp-content\/uploads\/2018\/06\/css\u9069\u5fdc-300x110.png 300w\" sizes=\"(max-width: 432px) 100vw, 432px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"Rails\u30a2\u30d7\u30ea\u3067\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u30a2\u30bb\u30c3\u30c8\u306b\u542b\u307e\u308c\u3066\u3044\u308b\uff23\uff33\uff33\u3068JavaScript\u306f\u5168\u3066\u8aad\u307f\u8fbc\u3080\u3088\u3046\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u3066\u3044\u307e\u3059\u3002 \u305f\u3060\u3001\u73fe\u5b9f\u3068\u3057\u3066\u306f\u30da\u30fc\u30b8\u3054\u3068\u306b\u8aad\u307f\u8fbc\u307e\u308c\u308b\uff23\uff33\uff33\u3068JavaScript\u3092\u5909\u66f4\u3057\u305f\u3044\u3068\u3044\u3046\u3053\u3068 [&hellip;]","protected":false},"author":1,"featured_media":4265,"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\/4609"}],"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=4609"}],"version-history":[{"count":13,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/4609\/revisions"}],"predecessor-version":[{"id":20549,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/4609\/revisions\/20549"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/4265"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4609"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}