Rails活动存储无法自动加载常量ActiveStorage :: Blob :: Analyzable [英] Rails Active storage Unable to autoload constant ActiveStorage::Blob::Analyzable

查看:138
本文介绍了Rails活动存储无法自动加载常量ActiveStorage :: Blob :: Analyzable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将Rails从5.1.4更新为5.2,并删除了Papaerclip以使用Active Storage.我正在使用digitalocean空间.在开发环境中,我已经在storage.yml中设置了凭据,以将图像保存到digitalocean.

I've updated rails from 5.1.4 to 5.2 and remove Papaerclip to use Active Storage. I'm using digitalocean spaces. In my development env I've setted credentials in storage.yml to save images to digitalocean.

我在gemfile中添加了 aws-sdk-s3 gem(没有版本,可能是这个问题吗?).

I've added aws-sdk-s3 gem in gemfile (without version, may be this the problem?).

我运行db:migrate进行活动存储.

但是当我要提交带有图像上传html标签的表单时,我会收到此错误:

But when I'm going to submit the form with an image upload html tag, i receive this error:

无法自动加载常量ActiveStorage :: Blob :: Analyzable.

Unable to autoload constant ActiveStorage::Blob::Analyzable.

有人可以帮助我吗?

推荐答案

如果要从Rails的较旧版本更新到包含ActiveStorage的版本,则创建样板文件storage.yml很重要.您可能已通过

If you are updating from an older version of Rails to a version that contains ActiveStorage, it is important to create the boiler plate storage.yml. You may have stored your credentials through

rails credentials:edit

您的S3设置可能与此类似:

And your setup for S3 might look similar to this:

amazon:
  service: S3
  access_key_id: <%= Rails.application.credentials.aws[:access_key_id] %>
  secret_access_key: <%= Rails.application.credentials.aws[:secret_access_key] %>
  region: <%= Rails.application.credentials.aws[:region] %>
  bucket: <%= Rails.application.credentials.aws[:bucket] %>

我遇到的问题是,当我将凭据保存在storage.yml上时,所有密钥都保存为注释.运行EDITOR='atom --wait' rails credentials:edit(使用您正在使用的编辑器;在此示例中,我使用的是atom),并确保没有任何项目通过#进行注释.关闭窗口时,您的凭据应自动保存并可以访问.

The issue that I had was that when I saved my credentials on storage.yml, all of the keys were saved as comments. Run EDITOR='atom --wait' rails credentials:edit (with the editor that you are using; in this example, I am using atom) and make sure that none of your items are commented through #'s. When you close the window, your credentials should automatically be saved and can be accessed.

希望有帮助!

这篇关于Rails活动存储无法自动加载常量ActiveStorage :: Blob :: Analyzable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆