我刚刚升级了5.1.4 . 应用程序到5.2,我正在尝试将Paperclip替换为ActiveStorage . 在尝试使用图像更新现有记录时,我收到以下错误:
无法自动加载常量ActiveStorage :: Blob :: Analyzable,预期/Users/Simon/.rvm/gems/ruby-2.4.0/gems/activestorage-5.2.0/app/models/active_storage/blob/analyzable.rb到定义它
在我的模型中:
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中:
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中:
config.active_storage.service = :amazon
在我看来:
<%= image_tag @gin.pic, class: "border shadow-lg" %>
我一直在读http://edgeapi.rubyonrails.org/classes/ActiveStorage/Blob/Analyzable.html但对我来说并没有多大意义 .
该错误让我在 app/models/active_storage/blob/analyzable.rb
找到该文件,但我在我的应用程序中看不到它?
我错过了什么?
2 回答
我有完全相同的错误 . 对我来说,这是因为缺少AWS S3的凭据(凭证中缺少凭证 . )
解决
虽然我已经
gem 'aws-sdk-s3', '~>1'
我没有require: false