LoginSignup
1
1

More than 3 years have passed since last update.

require_treeについて

Posted at

目次

①require_tree.とは
②記述されている場所
③読み込まれる流れ

①require_tree.とは

フォルダ配下にある全ファイルを対象として読み込むという意味。

app/assets/stylesheets/application.css
/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
 * vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
 * files in this directory. Styles in this file should be added after the last require_* statement.
 * It is generally better to create a new file per style scope.
 *
 *= require_tree . ←これ!この「.」はカレントディレクトリという意味。
 *= require_self
 */

上記のように書かれる。現在のディレクトリはstylesheetsなので、ディレクトリ内にあるファイルを全て読み込まれることになる。
「*=」と一見コメントアウトされているかのように見えるが、コメントアウトされているかに見えるが、実際はコードとして意味のある行になりまる。( コメントアウト行の先頭がイコールで始まる行はdirectiveと呼ばれ、Ruby on Railsがapp/assets を管理する際に用いられる記法です )

②記述されている場所

上記のように記載されている場所は、application.cssファイルに記述されている。

③読み込まれる流れ

app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
  <head>
    <title><%= yield(:tittle)%>|ニコッとできるキャリプランを</title>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
     上記の記述でapplication.cssファイルが読み込まれ,aplication.cssに記述されているrequire_tree.が発動する
    <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
  </head>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1