资产"application.js"在资产管道中不存在 [英] The asset "application.js" is not present in the asset pipeline

查看:93
本文介绍了资产"application.js"在资产管道中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Ruby ROR 框架中的新手.我尝试使用JQuery创建Web应用程序.我的步骤是:

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

  1. 添加了gem'jquery-rails'并从命令行执行了捆绑安装命令
  2. 将字符串 //= require jquery2 添加到 application.js 文件
  3. 现在,我尝试将文件包含到页面中.然后在 application.html.erb 文件中添加了段字符串 <%= javascript_include_tag "application" %>
  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" %>

我做错了什么?我在Google上搜索了此错误,但没有找到任何好的解释.

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

推荐答案

首先尝试重新启动服务器,通常不需要在资产中包含application.js文件.如果不起作用,则

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

在您的 config / initializer / assets.rb 文件中添加以下内容:

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

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

注意:添加资产文件后,请不要忘记重启服务器.如果您在Inilalizers中进行了任何更改,则必须重新启动服务器才能看到效果.

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.

这篇关于资产"application.js"在资产管道中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆