本文介绍了Active Storage Rails 5.2的Blob错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚升级了5.1.4.应用程式至5.2,并尝试将Paperclip换成ActiveStorage.在尝试使用图像更新现有记录时,出现以下错误:

I've just upgraded a 5.1.4. app to 5.2 and am trying to swap out Paperclip for ActiveStorage. At the moment when trying to update an existing record with an image, I get the following error:

在我的模型中:

has_one_attached :pic

在我的控制器中:

...

  def update
    respond_to do |format|
      if @gin.update(gin_params)
        format.html { redirect_to @gin, notice: 'Gin was successfully updated.' }
        format.json { render :show, status: :ok, location: @gin }
      else
        format.html { render :edit }
        format.json { render json: @gin.errors, status: :unprocessable_entity }
      end
    end
  end

...

 def gin_params   params.require(:gin).permit(:name, :text, :snippet,
 :pic, :slug, :abv, distillery_attributes: [:id, :name], botanical_ids:
 []) end

在storage.yml中:

In storage.yml:

   amazon:
    service: S3
    access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
    secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
    region: xx-xxxx-x
    bucket: xxxxxxx

我通过rails credentials:edit

在development.rb中:

In development.rb:

 config.active_storage.service = :amazon

在我看来:

<%= image_tag @gin.pic, class: "border shadow-lg" %>

我一直在阅读 http://edgeapi.rubyonrails.org/classes/ActiveStorage/Blob/Analyzable.html ,但这对我来说并没有太大意义.

I've been reading though http://edgeapi.rubyonrails.org/classes/ActiveStorage/Blob/Analyzable.html but it doesn't make too much sense to me.

该错误使我在app/models/active_storage/blob/analyzable.rb处查找文件,但在我的应用程序中看不到它?

The error has made me look for the file at app/models/active_storage/blob/analyzable.rb but I can't see it in my app?

我错过了什么?

推荐答案

已解决

虽然我已经拥有gem 'aws-sdk-s3', '~>1',但我没有require: false

Whilst I already had gem 'aws-sdk-s3', '~>1' I didn't have require: false

这篇关于Active Storage Rails 5.2的Blob错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 03:27