gpt4 book ai didi

html - CSS 样式表无法使用 Ruby on Rails:Sprockets::Rails::Helper::AssetNotFound 错误

转载 作者:太空宇宙 更新时间:2023-11-03 19:25:42 25 4
gpt4 key购买 nike

我正在尝试将 CSS 文件添加到我的 Rails 元素中。我创建了一个名为 style.css 的文件并将其放在/project/public 中。在我的 View 文件 (index.html.erb) 中,我添加了以下代码行:

<%= stylesheet_link_tag "style" %>

当我运行 rails server 时,出现以下错误:

    Sprockets::Rails::Helper::AssetNotFound in Articles#index
Showing /mnt/c/code/blog/app/views/articles/index.html where line #34

raised:

The asset **"style.css"** is not present in the asset pipeline.

我该如何解决这个问题?

最佳答案

The asset "style.css" is not present in the asset pipeline.

此消息表示您尚未将文件包含在相应文件夹中以与 Assets 管道 (/project/public) 进行交互。

为了使用 Assets 管道,您必须遵循一些规则:

首先:

将其放在指定文件夹(vendor 或 assets 或 lib)中,这是元素文件夹中的三个不同文件夹,assets pipeline 旨在搜索 list 中声明的​​文件或使用 stylesheet_link_tag 单独调用的文件。

然后:

stylesheet_link_tag 调用它。

阅读有关 Assets 管道搜索路径的更多信息 https://guides.rubyonrails.org/asset_pipeline.html#search-paths

旁注:

您还可以使用 rails 提供的应用程序 list assets/application.cssassets/application.js 并在您的 html 中调用它,而不是分别调用每个文件.. 这是 Assets 管道的一种意图。

写成:

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass and ERB. It allows assets in your application to be automatically combined with assets from other gems.

如果不在 list 中声明您的文件,您将丢失所有这些内置商品。

更多阅读 https://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives

关于html - CSS 样式表无法使用 Ruby on Rails:Sprockets::Rails::Helper::AssetNotFound 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55379018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com