10

I am creating a RoR-6 app and I get the following error thrown from application.html.erb file from this line:

javascript_include_tag 'application', 'data-turbolinks-track': 'reload'

I get the following error:

ActionView::Template::Error: The asset "application.js" is not present in the asset pipeline.

The app was created by running rails new myapp -d postgres

I am using rails 6.0.0.rc1

kyleboe
  • 157
  • 1
  • 8
Steveo00
  • 111
  • 1
  • 6

4 Answers4

14

You'll want to use javascript_pack_tag instead of javascript_include_tag:

javascript_pack_tag 'application', 'data-turbolinks-track': 'reload'

This is required because webpacker handles javascript compilation in Rails 6.

kyleboe
  • 157
  • 1
  • 8
  • 2
    Thanks. This solved the problem. I appreciate your quick response. – Steveo00 May 01 '19 at 00:50
  • 1
    Worth noting that it's incorrect to say webpacker handles asset compilation in Rails 6.0.0 - webpacker handles _javascript_ compilation only by default. Rails Asset Pipeline and Sprockets is still used for CSS, images and other asset types. – jmcd May 05 '19 at 17:28
  • Having the same problem in production and using the javascript_pack_tag, any idea why? – mrcaramori Jul 19 '20 at 19:07
2

If you do not want to use Webpack, add the following to config/initializers/assets.rb:

Rails.application.config.assets.precompile += %w(application.js)
Artur INTECH
  • 6,024
  • 2
  • 37
  • 34
1

Running yarn build solved the issue for me (which in the first place was caused by running rails assets:clobber)

Fed
  • 1,696
  • 22
  • 29
  • damn, I found my own solution to help me 3 months down the line. can confirm again that this works. – Fed Nov 16 '22 at 16:38
0

Place this line in the application.html.erb:

<%= javascript_pack_tag 'application' %>

This worked on my end.

ouflak
  • 2,458
  • 10
  • 44
  • 49