Unable to autoload constant ActiveStorage::Blob::Analyzable

时间:2019-01-09 22:19:07

标签: ruby-on-rails ruby rails-activestorage

I looked at every possible solution regarding this error but nothing solved it.

Every time I try to upload an image, I receive this error:

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

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]

In config/application.rb I have require 'active_storage/engine' uncommented.

In config/environments/development.rb I have config.active_storage.service = :local set up.

I ran rails active_storage:install and rails db:migrate.

The name of the model is user_test

class UserTest < ApplicationRecord
  has_one_attached :image
end

I have this in app/controllers/user_tests_controller.rb

def user_test_params
  params.require(:user_test).permit(:title, :caption, :image)
end 

**config/storage.yml*

test:
  service: Disk
  root: <%= Rails.root.join("tmp/storage") %>

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

I am really clueless as to why it isn't working.

2 个答案:

答案 0 :(得分:5)

您是否有机会在pragma solidity >0.5.2; 中设置了config.active_storage.service = :amazon

我遇到了以上错误,最终是因为我有上述行,但是未设置AWS env vars。

答案 1 :(得分:1)

确保检查所有存在的环境变量:

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

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