LoginSignup
11
13

More than 5 years have passed since last update.

Rails4でのjavascript_include_tagで指定したはずなのに適応されない。

Posted at

javascript_include_tag Rails 4 generating "/javascripts/" instead of "/assets" in production - Stack Overflow

ここの質問のように、javascript_include_tagを使って特定のjsファイルを読み込もうとした時に、Production環境だと、/assets/hoge.jsじゃなくて、/javascripts/hoge.jsを指定していた。

解決策

The default matcher for compiling files includes application.js, application.css and all non-JS/CSS files (this will include all image assets automatically) from app/assets folders including your gems:

The Asset Pipeline — Ruby on Rails Guides

どうやら Rails4でassets precompileされるのは、app/assets 以下に入っている、application.js, application.css, .js, .css以外のファイルだそうです。

なので、

config/environments/production.rb

config.assets.precompile += ['hoge.js', 'hoge.css']

みたいな感じで書いておくとassets precompileしてくれます。

11
13
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
11
13