【问题标题】:RSpec Request Warning - Rails 5.1 Upgrade - The Asset not present in asset pipelineRSpec 请求警告 - Rails 5.1 升级 - 资产管道中不存在资产
【发布时间】:2017-06-02 03:54:10
【问题描述】:

我正在将 Rails 5.0.1 应用程序升级到 Rails 5.1 并遇到一些弃用警告。我能够解决除一个以外的所有问题。

我四处寻找,但没有找到明确的答案。

背景

这是一个刚刚完成的应用。我刚刚将 rails 版本更新到 5.1

我有一些 RSpec 请求规范。他们在(设计)登录中测试重定向。此错误显示在这些规范中。

控制器规格运行良好。我在有关 css、js、图像等的请求规范中看到此警告。

我确实在资产管道中有dashboard.js。还有一个app/assets/javascripts/dashboard.coffee 文件。

# config/initializers/assets.rb
Rails.application.config.assets.precompile += %w[
  sites.js
  sites.css
  admin.js
  admin.css
  header.js
  dashboard.js
  dashboard.css
  setup.js
  setup.css
]

警告

这是我看到的警告。

DEPRECATION WARNING: The asset "header.js" is not present in the asset pipeline.Falling back to an asset that may be in the public folder.
This behavior is deprecated and will be removed.
To bypass the asset pipeline and preserve this behavior,
use the `skip_pipeline: true` option.
  (called from _app_views_layouts_dashboard_html_slim__2366450786595837886_80483400 at /home/ziyan/Work/Brevica/churchfoyer/app/views/layouts/dashboard.html.slim:17)

DEPRECATION WARNING: The asset "dashboard.js" is not present in the asset pipeline.Falling back to an asset that may be in the public folder.
This behavior is deprecated and will be removed.
To bypass the asset pipeline and preserve this behavior,
use the `skip_pipeline: true` option.
(called from _app_views_layouts_dashboard_html_slim__2366450786595837886_80483400 at /home/ziyan/Work/Brevica/churchfoyer/app/views/layouts/dashboard.html.slim:18)
DEPRECATION WARNING: The asset "dashboard.css" is not present in the asset pipeline.Falling back to an asset that may be in the public folder.
This behavior is deprecated and will be removed.
To bypass the asset pipeline and preserve this behavior,
use the `skip_pipeline: true` option.
  (called from _app_views_layouts_dashboard_html_slim__2366450786595837886_80483400 at /home/ziyan/Work/Brevica/churchfoyer/app/views/layouts/dashboard.html.slim:19)

DEPRECATION WARNING: The asset "logos/logo-white.png" is not present in the asset pipeline.Falling back to an asset that may be in the public folder.
This behavior is deprecated and will be removed.
To bypass the asset pipeline and preserve this behavior,
use the `skip_pipeline: true` option.
  (called from _app_views_layouts_dashboard__sidebar_html_slim___2324799200884164274_84919380 at /home/ziyan/Work/Brevica/churchfoyer/app/views/layouts/dashboard/_sidebar.html.slim:3)

我尝试了什么

  • 手动预编译资产没有解决

感谢有关如何解决此警告的任何建议。

我认为资产管道已被绕过规范。

【问题讨论】:

    标签: ruby-on-rails ruby rspec ruby-on-rails-5.1


    【解决方案1】:

    您需要在assets.rb 文件中添加dashboard.js 才能知道它需要预编译的rails..

    #/config/initializers/assets.rb
    Rails.application.config.assets.precompile += %w( dashboard.js )
    

    添加这一行,其实你只需要取消注释并添加文件名即可。

    【讨论】:

    • 这些文件在哪里?
    • 我发现将scss 文件放在public 文件夹下,使用第三方sass 观察程序和编译器并跳过assets 管道在使用browsersync 进行实时重新加载时可以提供更好的性能。
    【解决方案2】:

    我将 Rails 升级到 5.1 后遇到了同样的问题

    我假设您将一些资产保存在 ./public 文件夹中

    您可以将资产从 ./public 移动到 ./app/assets 文件夹中。或者只是添加skip_pipeline: true 选项,如下所示:

    image_url("body-bg.gif", skip_pipeline: true)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-18
      • 2018-09-01
      • 2017-12-27
      • 2023-03-26
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      相关资源
      最近更新 更多