0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[個人用メモ]特定のページにだけjsファイルを読み込ませる

Last updated at Posted at 2018-07-18

目的

  • ポートフォリオを作成している時にjsファイルを個別に読み込ませた時のメモ

前提条件

  • ruby 2.4.1
  • Rails 5.1.6

1. 読み込ませたいファイルをapp/assets/javascripts/配下に設置

  • app/assets/javascripts/comment_form.jsにファイル設置

Image from Gyazo

2. 読み込ませたいviewファイルの中身の下部に読み込みコードを記述

app/views/posts/new.html.erb

# ファイルの中身の下に記述する

<%= javascript_include_tag 'comment_form' %>

3. Asset Pipelineにパスを通す

Asset Pipelineにパスを通していない場合

Image from Gyazo


config/initializers/assets.rbにpathを設定

config/initializers/assets.rb
Rails.application.config.assets.precompile += %w( comment_form.js )

Image from Gyazo

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?