小编NZi*_*ool的帖子

Rails 6 中的 ActionView::Template::Error (资产不存在于资产管道中。)

我将图像“jumbotron.jpeg”放置在app/assets/images文件夹中,我在视图中使用该图像:

<div class="jumbotron" style="background: url(<%= image_path 'jumbotron' %>);  no-repeat center center fixed;">
Run Code Online (Sandbox Code Playgroud)

它在开发中运行良好,但当我推送到生产时,我遇到了以下错误:

ActionView::Template::Error (The asset "jumbotron" is not present in the asset pipeline.):
Run Code Online (Sandbox Code Playgroud)

这里还有另一个主题提到同一问题: Rails - 使用 image_tag 时资产不存在于资产管道中

我找到的解决方案是将以下内容设置为 true config/environments/production.rb

  config.assets.compile = true
Run Code Online (Sandbox Code Playgroud)

它确实有效,但它使加载页面变得非常慢。这篇文章还解释了为什么将 config.assets.compile 设置为 true 是一个坏主意: https: //stackoverflow.com/a/8827757/11293450

因此,我尝试做的(设置回来后config.assets.compile = false)是在本地预编译资产(参见https://guides.rubyonrails.org/asset_pipeline.html#local-precompilation)。

我更改config/environments/production.rb为添加这一行:

  config.assets.prefix = "/dev-assets"
Run Code Online (Sandbox Code Playgroud)

然后跑:

rake assets:precompile 
Run Code Online (Sandbox Code Playgroud)

public/ 文件夹中创建了一个dev-assets文件夹文件夹。

在服务器上部署之前,我将文件推送到版本控制:

  1. git push从我的本地环境到Github
  2. git pull在我的生产服务器(VPS)上,然后:
  3. bundle install --deployment --without development …

ruby-on-rails

3
推荐指数
1
解决办法
5596
查看次数

nginx: [警告] 0.0.0.0:443/0.0.0.0:80 上的冲突服务器名称“www.site.com”,被忽略

在 certbot 自动续订上运行试运行时,我收到以下警告:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/example.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - …
Run Code Online (Sandbox Code Playgroud)

nginx

1
推荐指数
1
解决办法
2624
查看次数

标签 统计

nginx ×1

ruby-on-rails ×1