ActionView::Template::Error(资源“application.css”不存在于资源管道中。)

问题描述 投票:0回答:1

在 Rails 7 中从 webpacker 转移到 importmaps 后。无论我如何解决它,我都会不断收到此错误。以下是错误的输出。

I, [2022-12-02T11:33:16.828698 #2401]  INFO -- : [ca024b47-6054-444f-ab01-7f92d98e099f] Started GET "/" for 127.0.0.1 at 2022-12-02 11:33:16 +0500
I, [2022-12-02T11:33:16.858168 #2401]  INFO -- : [ca024b47-6054-444f-ab01-7f92d98e099f] Processing by Devise::SessionsController#new as HTML
I, [2022-12-02T11:33:17.079797 #2401]  INFO -- : [ca024b47-6054-444f-ab01-7f92d98e099f]   Rendered /Users/hamzaaamir/.rvm/gems/ruby-3.1.0/gems/devise-4.8.1/app/views/devise/sessions/new.html.erb within layouts/application (Duration: 10.1ms | Allocations: 3457)
I, [2022-12-02T11:33:17.080678 #2401]  INFO -- : [ca024b47-6054-444f-ab01-7f92d98e099f]   Rendered layout layouts/application.html.erb (Duration: 11.0ms | Allocations: 4035)
I, [2022-12-02T11:33:17.080831 #2401]  INFO -- : [ca024b47-6054-444f-ab01-7f92d98e099f] Completed 500 Internal Server Error in 223ms (ActiveRecord: 74.8ms | Allocations: 17972)
F, [2022-12-02T11:33:17.081562 #2401] FATAL -- : [ca024b47-6054-444f-ab01-7f92d98e099f]   
[ca024b47-6054-444f-ab01-7f92d98e099f] ActionView::Template::Error (The asset "application.css" is not present in the asset pipeline.
):
[ca024b47-6054-444f-ab01-7f92d98e099f]      6:     <%= csrf_meta_tags %>
[ca024b47-6054-444f-ab01-7f92d98e099f]      7:     <%= csp_meta_tag %>
[ca024b47-6054-444f-ab01-7f92d98e099f]      8: 
[ca024b47-6054-444f-ab01-7f92d98e099f]      9:     <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
[ca024b47-6054-444f-ab01-7f92d98e099f]     10:     <%= javascript_importmap_tags %>
[ca024b47-6054-444f-ab01-7f92d98e099f]     11:   </head>
[ca024b47-6054-444f-ab01-7f92d98e099f]     12: 
[ca024b47-6054-444f-ab01-7f92d98e099f]   
[ca024b47-6054-444f-ab01-7f92d98e099f] app/views/layouts/application.html.erb:9

我已经运行了 importmaps rake 任务并添加了

sassc-rails
来编译我的 CSS 文件。它在开发环境中运行良好,但在生产环境中会产生错误。我也跑过
rails assets:precompile

我的代码在assets/config/manifest.js

//= link_tree ../images
//= link_directory ../stylesheets .css
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js

我的代码在assets/stylesheets/application.scss

@import "bootstrap";
@import "./dashboard.scss";
@import "./sidebar.scss";
css ruby-on-rails ruby asset-pipeline ruby-on-rails-7
1个回答
0
投票

对于 rails 7 运行以下命令

rails assets:precompile

这将在您的公共文件夹中创建一个资产文件夹。然后重新启动服务器。

© www.soinside.com 2019 - 2024. All rights reserved.