首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法自动加载常量ActiveStorage::Blob::Analyzable

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

Stack Overflow用户
提问于 2019-01-09 22:19:07
回答 2查看 2.4K关注 0票数 0

我查看了关于这个错误的每一个可能的解决方案,但是没有解决它。

每当我试图上传图片时,我都会收到以下错误:

Unable to autoload constant ActiveStorage::Blob::Analyzable, expected /usr/local/lib/ruby/gems/2.5.0/gems/activestorage-5.2.2/app/models/active_storage/blob/analyzable.rb to define it

Gemfile

代码语言:javascript
复制
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.1'

gem 'rails', '~> 5.2.0'
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
# Causing crashes. Removing for now
# gem 'bootsnap', '>= 1.1.0', require: false

# Well maintained fork with several patches and compatability for Rails 5.x
# If we need to we can fork this and take ownership of it. Much better than building from scratch.
# gem 'casino', git: "https://github.com/identification-io/CASino.git", branch: "master"
gem 'casino', git: "https://github.com/webappsllc/CASino.git", branch: "master"
# gem 'casino', path: '/Users/justin/dev/oss/CASino'
gem 'grape', '~> 1.1.0' # Pinned

gem 'wisper', '~> 2.0'
gem 'rack-cors', require: 'rack/cors'

# Form Objects
gem "reform", ">= 2.2.0"
gem "reform-rails"
gem "dry-validation"

# Free optimization
gem 'fast_blank'

# Hashids to obscure legacy_ids
gem 'hashids'

# Send Emails via Amazon SES
gem 'aws-sdk-rails'

# Upload Files via Amason S3
gem "aws-sdk-s3", require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'guard-rspec', require: false
  gem 'dotenv-rails', require: 'dotenv/rails-now'
  gem 'spring-commands-rspec'
  gem 'parallel_tests', group: [:development, :test]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'grape_on_rails_routes'
  gem "better_errors"
  gem "binding_of_caller"
  gem "letter_opener"
  gem 'letter_opener_web', '~> 1.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15', '< 4.0'
  gem 'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem 'chromedriver-helper'
  gem 'factory_bot'
  gem 'rspec'
  gem 'rspec-rails'
  gem 'database_cleaner'
  gem 'faker'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
# gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

config/application.rb中,require 'active_storage/engine'没有注释。

config/environments/development.rb中,我设置了config.active_storage.service = :local

我负责rails active_storage:installrails db:migrate

模型的名称是user_test

代码语言:javascript
复制
class UserTest < ApplicationRecord
  has_one_attached :image
end

我在app/controllers/user_tests_controller.rb里有这个

代码语言:javascript
复制
def user_test_params
  params.require(:user_test).permit(:title, :caption, :image)
end 

**config/storage.yml*

代码语言:javascript
复制
test:
  service: Disk
  root: <%= Rails.root.join("tmp/storage") %>

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

我真的不知道为什么它不起作用。

EN

回答 2

Stack Overflow用户

发布于 2019-01-16 00:03:39

您的development.rb中有设置development.rb的可能性吗?

我得到了上面的错误,结果是因为我有上面的行,但是AWS env没有设置。

票数 5
EN

Stack Overflow用户

发布于 2020-02-06 17:07:02

请确保检查所有环境变量是否都存在:

  • AWS访问密钥
  • AWS密钥
  • 桶名

检查环境变量的拼写,以确保它们与storage.yml配置文件匹配。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54119226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档