Errno::ENOENT in ActiveStorage::DiskController#show



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/environment/production.rb

config.active_storage.service = :local

config/environment/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

导轨 5.2.4

使用:

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

  2. 生产中的Active_Storage(无法加载资源:500 错误(

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

  4. Rails API ActiveStorage:获取公有 URL 以显示来自 AWS S3 存储桶的图像?

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

谢谢机甲。

最新更新