我已经尝试了一个多星期,试图将自定义模板放入版本6的Rails应用程序中。无论是使用Yarn还是直接在html中引用,都找不到资产。
获取http://localhost:3000/assets/vendors/iconfonts/mdi/css/materialdesignicons净值:: ERR_ABORTED 404(未找到)
资产位于Vendor文件夹中。请注意,该文件夹内还有另一个名为“ vendors”的文件夹,这不是错误。
我的application.js中有
igraph
我还尝试了遵循资产管道最佳实践的另一种模板,但现在这种模板不起作用了。
This is the path wehre the template is.
我的application.css是:
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("jquery")
require("popper.js")
require("bootstrap")
require('vendors/js/vendor.bundle.base')
require('vendors/js/vendor.bundle.addons')
require('js/shared/off-canvas')
require('js/shared/misc')
但是我也尝试了其他方法,使用require,并且正如我之前所说,将其直接链接到HTML中,现在就像这样:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
* vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/
@import "vendors/iconfonts/mdi/css/materialdesignicons";
@import "vendors/iconfonts/ionicons/css/ionicons";
@import "vendors/iconfonts/typicons/src/font/typicons";
@import "vendors/iconfonts/flag-icon-css/css/flag-icon";
@import "vendors/css/vendor.bundle.base";
@import "vendors/css/vendor.bundle.addons";
@import "css/shared/style";
@import "css/demo_1/style";
我已经运行了以下命令:
<!DOCTYPE html>
<html>
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>School</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_packs_with_chunks_tag 'application' %>
<link rel="shortcut icon" href="/images/favicon.png" />
</head>
<body>
...
rails webpacker:install
另外,我还更改了application.rb
rails assets:precompile
,但似乎无济于事,我总是得到一个没有主题的页面。
Rails版本:6.0.2.1
Ruby版本:2.6.5p114(2019-10-01版本67812)[x64-mingw32]
节点版本:v12.14.1
纱线版本:1.21.1
SO:Windows 10
我不知道该如何解决该“未找到”错误。
答案 0 :(得分:1)
Using Rails-UJS in JS modules (Rails 6 with webpacker)
您的application.js需要移动到其他文件夹中,以便webpacker能够使用它。
app / javascript / packs / application.js