【问题标题】:The asset "logo.png" is not present in the asset pipeline资产管道中不存在资产“logo.png”
【发布时间】:2023-03-26 13:45:01
【问题描述】:

在 Rails 5.1.3 中 我更改了 app/assets/images 中的徽标文件 然后错误不知道要修复什么。有谁知道吗?

The asset "logo.png" is not present in the asset pipeline.

已经尝试重启 rails、rails clean、rails 或 rails assets:precompile

这里是我的 config/initializers/assets.rb

# Be sure to restart your server when you modify this file.

# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'

# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

【问题讨论】:

    标签: ruby-on-rails asset-pipeline ruby-on-rails-5.1


    【解决方案1】:

    我遇到了同样的问题,尝试了这篇文章中提出的所有解决方案,但没有人奏效……最后,重命名图像确实解决了问题,从“compuLab50-2.png”到“compusuno.png”。 .. 我还在“layouts/application.html.erb”文件中添加了 。这是一个非常烦人且令人沮丧的问题,我认为这是一个 Rails 错误(顺便说一下,我正在使用带有 webpacker 的 Rails 6.1.3,我认为这没有多大帮助)

    【讨论】:

      【解决方案2】:

      对于 rails 6,确保您的图像位于内部

      /app/assets/images/
      

      那么简单

      <%= image_tag("mylogo.png", size: '200x75', alt: "logo") %>
      

      【讨论】:

        【解决方案3】:

        解决此问题的最佳方法是将图像文件放在公共文件夹中,然后在 HTML.erb 文件中使用类似这样的代码。这是我个人的经验

        <img src="/logo.png" alt="" />
        

        【讨论】:

        • 感谢您的提示。如果您不想使用资产管道,则此方法有效。所以在这种情况下我不会推荐它,但对我来说它很有帮助
        【解决方案4】:

        因为这里没有发布...对我来说就像重启 Rails 服务器一样简单。

        【讨论】:

          【解决方案5】:

          这是我为解决问题所做的 假设我的代码没有问题并且可以正常工作:

          1. 使用以下命令清理 /tmp/assets 中的资产缓存:
          $rake tmp:clear
          

          正如here所说的

          1. 使用此命令再次预编译资产:
          $rake assets:precompile
          

          【讨论】:

            【解决方案6】:

            我遇到了类似的问题。解决方案是在图像上添加文件扩展名。

            = image_tag 'logo', alt: ''
            

            = image_tag 'logo.jpg', alt: ''
            

            【讨论】:

            • 如果是js文件呢?
            【解决方案7】:

            尝试这样做

            先去

            app/assets/images
            

            第二次创建文件夹标志

            app/assets/images/logos
            

            第三次将图像放入徽标

            app/assets/images/logos/logo.png
            

            最后在你的应用程序中放上这段代码

            <%= link_to image_tag("logos/logo.png"), root_path %>
            

            它无处不在

            【讨论】:

            • 太棒了!为我工作
            • 在将rails 5更新到6并添加没有扩展名的图像标签后,可能会在生产中出错,但它会在开发中找到,可以修复,如添加图像扩展名。跨度>
            猜你喜欢
            • 1970-01-01
            • 2017-12-27
            • 1970-01-01
            • 2021-09-11
            • 1970-01-01
            • 1970-01-01
            • 2019-09-18
            • 1970-01-01
            • 2018-09-01
            相关资源
            最近更新 更多