【问题标题】:Errno::ENOENT in ActiveStorage::DiskController#showActiveStorage::DiskController#show 中的 Errno::ENOENT
【发布时间】:2020-05-14 21:00:13
【问题描述】:

app/models/user.rb

class User < ApplicationRecord
has_one_attached :avatar
end

app/controllers/admin/home_controller.rb

class Admin::HomeController < Admin::BaseController
  def show
  end
end

app/views/admin/home/show.html.slim

    - if current_user.avatar.attached?
      / - binding.pry
      = image_tag current_user.avatar.variant(resize: "160x160"), alt: 'User Image', class: 'img-circle elevation-2'
    - else
      = image_tag 'backend/default-avatar.png', alt: 'User Image', class: 'img-circle elevation-2'

config/environments/production.rb

config.active_storage.service = :local

config/environments/development.rb

config.active_storage.service = :local

config/storage.yml

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

我在环境中工作:开发。 但它在环境中不起作用:生产

Errno::ENOENT in ActiveStorage::DiskController#show
No such file or directory @ rb_file_s_mtime - /apps/example.com/releases/20200129093910/storage/kD/vP/kDvP9igiNZ58NMWhx1zAiKoC

Rails 5.2.4

使用:

  1. https://edgeguides.rubyonrails.org/configuring.html#configuring-active-storage

  2. Active_Storage (Failed to load resource: 500 error) in Production

  3. https://github.com/rails/rails/issues/31581

  4. Rails API ActiveStorage: Get Public URL to display image from AWS S3 Bucket?

【问题讨论】:

  • 您的生产服务器中有storage 目录吗?
  • 是的,我有/apps/example.com/current/storage目录
  • 还有/apps/example.com/releases/20200129093910

标签: ruby-on-rails-5


【解决方案1】:
mkdir public/storage

config/deploy.rb

set :linked_dirs, %w{tmp/pids tmp/cache tmp/sockets vendor/bundle public/uploads public/storage}

运行命令

bundle exec cap production linked_files:upload_dirs

谢谢mechnicov

【讨论】:

    猜你喜欢
    • 2020-07-31
    • 1970-01-01
    • 2012-03-16
    • 2019-10-20
    • 2019-10-23
    • 2017-05-29
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多