【问题标题】:Javascript browser console error 404 (Not Found)Javascript 浏览器控制台错误 404(未找到)
【发布时间】:2016-11-23 14:50:14
【问题描述】:

我在目录中创建了我的 javascript:

App/assets/javascript/product/products.js

在我的 Haml index.html.haml 文件中,我已包含此代码以引用我的 js.file:

= javascript_include_tag '产品'

config / application.rb 中我也包含了:

config.assets.precompile += ['products.js']。

但是,当我的浏览器重新加载时,我在控制台中显示一条红线错误

GET http://localhost:3000/javascripts/products.js 404(未找到)产品:65。

为什么它是从 javascripts/products.js 获取而不是通过我将脚本放在那里的产品目录文件?

在脚本中,如果我有代码警报,它会被触发,但如果代码是 jquery,它将不会运行。

更新答案: 在 haml 文件 index.html.haml 中使用:

=javascript_include_tag(product/products.js)

【问题讨论】:

    标签: javascript jquery ruby-on-rails ruby-on-rails-4


    【解决方案1】:

    /config/initializers/assets.rb

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

    在你的Haml index.html.haml文件中

    = javascript_include_tag :products
    

    试试看

    【讨论】:

    • 嗨 Serhii 它仍然无法正常工作。引导导航活动类没有响应,控制台仍然显示第 69 行:“”""
    • 嗨 Serhii 它在 Haml 文件中更改后可以工作,改为:=javascript_include_tag(product/products.js)
    猜你喜欢
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 2016-12-05
    • 1970-01-01
    相关资源
    最近更新 更多