Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The asset "application.js" is not present in the asset pipeline

I'm new in Ruby and in ROR framework. I try to create web app with JQuery. My steps are:

  1. Added gem 'jquery-rails' and executed bundle install command from command line
  2. String //= require jquery2 added into application.js file
  3. Now I try include file into page. And I added in section string <%= javascript_include_tag "application" %> into application.html.erb file

when I try to see page in browser I see error with message:

Sprockets::Rails::Helper::AssetNotFound in LandingPage#index
The asset "application.js" is not present in the asset pipeline.
<%= javascript_include_tag "application" %>

What I doing wrong? I googled about this error, but I didn't found anything good explained.

like image 225
Alex Avatar asked Jul 21 '17 12:07

Alex


People also ask

What is asset pipeline in JavaScript?

1 What is the Asset Pipeline? The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass, and ERB.

How do you Precompile an asset?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

What is Webpacker?

Webpacker is a Rails wrapper around the webpack build system that provides a standard webpack configuration and reasonable defaults.

What does rake assets Precompile do?

RAILS_ENV=production tells Rails to compile the production version of the assets. assets:precompile is a Rails provided rake task that has instructions for compiling the assets.


1 Answers

I also ran in this error with Rails 6 (with webpack) using the syntax javascript_include_tag in the application.html.erb file.

With rails 6 and webpack use:

<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
like image 162
Rudolf Fäder Avatar answered Sep 23 '22 16:09

Rudolf Fäder