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 1 year has passed since last update.

javascriptの外部ファイルの読み込む

Posted at

外部ファイルの接続

assets.rb
.
.
.
Rails.application.config.assets.precompile += %w( *.js )
rake restart

読み込みたいHTMLファイルに書き込む

  <%= javascript_include_tag "hogehoge.js" %>

これで成功か?

Sprockets::Rails::Helper::AssetNotPrecompiledError in *********

Showing /Users/***///app/views//*****.html.erb where line #6 raised:

Asset hogehoge.js was not declared to be precompiled in production.
Declare links to your assets in app/assets/config/manifest.js.

//= link hogehoge.js

and restart your server

//= link hogehoge.js

これをapp/assets/config/manifest.jsに入力すればいいのか。

これで成功した。

出典

感想

これで外部ファイルから読み込むことができた。
しかし
他の方法も知りたい。
scriptタグから外部ファイルを読み込むことができなかったからだ。

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?