【问题标题】:ActiveStorage::FileNotFoundError but the file actually existsActiveStorage::FileNotFoundError 但文件实际存在
【发布时间】:2020-06-04 23:10:23
【问题描述】:

我正在开发这个 Rails 6.0.21 应用程序(ruby 2.5.5),并使用 puma 3.12.2 作为开发 Web 服务器和带有本地磁盘服务的 ActiveStorage。

我的应用程序时不时会出现ActiveStorage::FileNotFoundError 错误。实际文件存在于磁盘上。模型正确响应 .attached?。

重新启动 puma 解决了该问题,然后该问题显然在稍后再次弹出……有些日子比其他日子更频繁。 这在带有 mod_passenger 的 Apache 上以相同的方式发生。

我做错了吗?

稍后编辑:下面是我相当标准的 puma、主动存储和错误配置

ActiveStorage 配置

development:
  service: Disk
  root: <%= Rails.root.join("storage") %>

彪马配置

# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port        ENV.fetch("PORT") { 3000 }

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }

# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }

# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
# preload_app!

# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart

错误输出

ActionView::Template::Error (ActiveStorage::FileNotFoundError):
    2:     TODO cache this like forever
    3: -->
    4: <% if (current_website.icon.attached? rescue nil) %>
    5:     <link rel="apple-touch-icon" href="<%= current_website.icon.variant(resize: "57x57").service_url %>" />
    6:     <link rel="shortcut icon" href="<%= current_website.icon.variant(resize: "16x16").service_url %>" />
    7:     <link rel="icon" href="<%= current_website.icon.variant(resize: "16x16").service_url %>" />
    8:

app/views/common/_page_head_icons.html.erb:5
app/views/common/_page_head.html.erb:61
app/views/layouts/admin.html.erb:3

【问题讨论】:

  • 能否通过代码 sn-ps 提供更多信息?以开发环境中ActiveStorage的配置和Puma的配置为例。错误的日志输出的副本也是如此。此类信息使提供帮助变得容易得多。
  • 谢谢,好点,我已经更新了帖子。

标签: ruby-on-rails puma rails-activestorage


【解决方案1】:

您能否分析应用程序以获取对 fs 的 IO 访问权限?或者至少尝试在不同的机器上,以防它与操作系统或 fs 相关?

【讨论】:

  • 有效的观点和好的建议,但我真的没有时间做这样的事情。难道这些东西不应该在没有任何麻烦的情况下工作吗?
猜你喜欢
  • 2021-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多