首页 > 解决方案 > Rails 5.2.3 创建文件时活动存储出现 Blob 错误

问题描述

我正在使用 rails 5.2.3,并且正在尝试将 ActiveStorage 用于新的脚手架议程。我已经按照这个教程

我想将文件本地保存在文件系统上。

当我想通过 web 表单创建一个新对象时,我收到以下错误:

无法自动加载常量 ActiveStorage::Blob::Analyzable,预期 /home/vagrant/.rvm/gems/ruby-2.6.2/gems/activestorage-5.2.3/app/models/active_storage/blob/analyzable.rb 来定义它

从邮件日志:

[错误] blogs create (NoMethodError) "Cannot load Rails.config.active_storage.service:\nundefined method `fetch' for n

当我刷新页面时,我得到:

nil:NilClass 的未定义方法“fetch”

我的定义

型号

has_one_attached :image

控制器

def create
  @blog = Blog.new(blog_params)
  .
  .
end

def blog_params
  params.require(:blog).permit(:name, :audit_comment, :image)
end

意见

= simple_form_for(blog) do |f|
  = f.error_notification
  .form-inputs
    = f.input :name, label: 'Name'

    = f.file_field :image

  = f.input :audit_comment
  .form-actions
    = f.button :submit

development.rb中:

config.active_storage.service = :local

我错过了什么?我已经按照此设置的建议rails active_storage:install运行和迁移

当我使用全新的 Rails 应用程序时,它运行良好。

标签: ruby-on-railsrails-activestorage

解决方案


推荐阅读