我刚刚升级了 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
但在我的应用程序中看不到它?
我错过了什么?