ruby-on-rails 请求的URL:/js/functions.js

ui7jx7zq  于 11个月前  发布在  Ruby
关注(0)|答案(2)|浏览(157)

当我在代码中引用JavaScript包的时候,我得到了一个错误。有没有什么我可能错过的想法?

application.js

import Rails from "@rails/ujs"
import Turbolinks from "turbolinks"

Rails.start()
Turbolinks.start()

require("jquery-3.5.1.min")
require("jquery-ui-1.12.1")
require("dataTables.fnSetFilteringDelay")
require("jquery.dataTables.columnFilter-1.5.6")
require("application_default")

字符串

application.html.erb

<%= javascript_pack_tag 'application', 'jquery-3', 'jquery-ui-1', 'jquery', 'FixedHeader-2', 'ColVis-1', 'rails': 'reload' %>


的数据

vsikbqxv

vsikbqxv1#

您丢失了相应的public/packs/js/*.js文件。有两个解决方案:
只编译包,让rails服务器在刷新时处理重新编译

bin/webpack

字符串
在开发中最好运行dev server,当你的文件改变时它会编译。

bin/webpack-dev-server


请注意你的文件结构和不同的 tag helpers做什么:

app/
  assets/                # used by sprockets aka rails asset pipeline
    stylesheets/
      application.css    # stylesheet_link_tag 'application'
                         #  this is not old syntax; very much current and recommended in rails 7
    javascripts/
      application.js     # javascript_include_tag 'application'

  javascript/            # used by rails webpacker
    packs/               # keep this folder neat; don't dump everything in here
      application.js     # javascript_pack_tag 'application'
                         #  use this file to import packages from node_modules
    styles/
      application.css    # stylesheet_pack_tag 'application'
                         #  must be imported in packs/application.js
                         #  import "styles/application"
  
  node_modules/          # use yarn or npm to add js packages, don't put them in 'packs'

c0vxltue

c0vxltue2#

如果没有其他工作为您服务:

1.运行bin/webpack && rake assets:precompile
1.确保rails在运行时没有试图编译资源,并且它可以从公共文件夹读取你的资源:

# production.rb 
config.public_file_server.enabled = true
config.assets.compile = false

字符串
1.运行rails s

相关问题