gpt4 book ai didi

heroku - Rails : application. css 不在 Assets 管道中

转载 作者:行者123 更新时间:2023-12-03 22:48:24 24 4
gpt4 key购买 nike

我知道这是一个老问题,但没有答案可以解决我的问题。
我是 Ruby on Rails 的新手,刚刚使用 PostgreSQL 数据库创建了项目,只是为了能够将项目上传到 Heroku。
当我启动 Rails 服务器时,我收到错误“ Assets 管道中不存在 application.css”。
我正在使用 bootstrap 4 gem,这要求您将 applications.css 重命名为 application.scss。
我不知道出了什么问题。
我真的尝试了stackoverflow上的每个答案都没有成功:(
请帮帮我,我做错了什么?
这是我得到的错误:
enter image description here

最佳答案

好的,第一件事。

你有没有config.serve_static_files = true设置在您的 production.rb文件下 config/environment文件夹。

由于我们在 NGINX 后面运行,在我们的例子中它看起来像 config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
第二件事。你做了吗rails assets:precompile在将其上传到服务器之前?

第三件事是。您是否尝试调用您的文件 application.css.scss ,并重做 rails assets:precompile ?

最后,并非最不重要的事情。您的 application.scss 怎么样?文件长什么样?

您是否删除了所有这些 *=并使用 @import代替 Bootstrap
它在文档中有很好的描述:

Import Bootstrap styles in app/assets/stylesheets/application.scss:

// Custom bootstrap variables must be set or imported before bootstrap. @import "bootstrap";



然后它说:

Make sure the file has .scss extension (or .sass for Sass syntax). If you have just generated a new Rails app, it may come with a .css file instead. If this file exists, it will be served instead of Sass, so rename it:

$ mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss Then, remove all the *= require and *= require_tree statements from the Sass file. Instead, use @import to import Sass files.

Do not use *= require in Sass or your other stylesheets will not be able to access the Bootstrap mixins and variables.



阅读更多 here

关于heroku - Rails : application. css 不在 Assets 管道中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56614166/

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