我正在尝试使用活动存储附加文件,并继续获取错误:
无法自动加载常量ActiveStorage::Blob::Analyzable,应为
/Users/sergeylukyanenko/.rvm/gems/ruby-2.6.0/gems/active storage-5.2.2/app/models/active\u storage/blob/analyzable.rb来定义它

Request
Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"L0czdSokZuL6CyRqMNEUAj/6AGRItCOZ/oIca6OGHtgsxD+ExTnZ1BtMdvFyHQTOEZ5/5LEd6dma23r1r8zIlA==",
 "event"=>
  {"name"=>"Coffee meetup",
   "date"=>"2019-01-28",
   "image"=>
    #<ActionDispatch::Http::UploadedFile:0x00007ff464e03278
     @content_type="image/jpeg",
     @headers="Content-Disposition: form-data; name=\"event[image]\"; filename=\"agile-software-development.jpg\"\r\n" + "Content-Type: image/jpeg\r\n",
     @original_filename="agile-software-development.jpg",
     @tempfile=#<File:/var/folders/6j/xkzm5glx2k9_ycr6c235lx2m0000gn/T/RackMultipart20190128-91451-1jdmov.jpg>>},
 "commit"=>"Create Event"}

这是我的事件控制器
def create
    if current_user
      @event = current_user.events.build(event_params)
    else
      @event = Event.new(event_params)
    end

    respond_to do |format|
      if @event.save
        format.html { redirect_to @event, :flash => { :success => 'Event was successfully created.' }}
        format.json { render :show, status: :created, location: @event }
      else
        format.html { render :new }
        format.json { render json: @event.errors, status: :unprocessable_entity }
      end
    end
  end

  def event_params
    params.require(:event).permit(:name, :date, :private, :image)
  end

和事件模型
class Event < ApplicationRecord
  validates :name, presence: true
  validates :date, presence: true

  has_one_attached :image
  belongs_to :user, optional: true
  has_many :tasks, dependent: :destroy

  scope :only_public,    -> { where(private: false) }
  scope :only_private,   -> { where(private: true)  }
  scope :by_recent,      -> { order(date: :asc) }

  def start_time
    self.date
  end
end

事件形式
<div class="field mt-4">
  <%= form.file_field :image %>
</div>

配置/存储.yml
test:
  service: Disk
  root: <%= Rails.root.join("tmp/storage") %>

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

# Use rails secrets:edit to set the AWS secrets (as shared:aws:access_key_id|secret_access_key)
amazon:
  service: S3
  access_key_id: <%= Rails.application.secrets.aws[:access_key_id] %>
  secret_access_key: <%= Rails.application.secrets.aws[:secret_access_key] %>
  region: us-east-1
  bucket: your_own_bucket

最佳答案

检查ActiveStorage installation
请运行下面的命令为ActiveStorage生成迁移。

rails active_storage:install

那么
rails db:migrate

编辑:如setup doc

09-27 09:25