The asset “application.js” is not present in the asset pipeline

三世轮回 提交于 2020-01-13 11:09:08

问题


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.


回答1:


first of all try to restart your server, generally there is no need to include application.js file in assets. if it doesn't work then

add below in your config / initializer / assets.rb file:

Rails.application.config.assets.precompile += %w(application.js)

Note: after adding in your assets file, don't forget to restart your server. If you do any changes in Inilalizers, you have to restart the server to see the effects.




回答2:


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' %>


来源:https://stackoverflow.com/questions/45237486/the-asset-application-js-is-not-present-in-the-asset-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!