Why am I getting unititialized constant in my Rspec model test? - ruby-on-rails

I'm trying to create a test with Rspec in my rails application but I keep getting the following error.
uninitialized constant Build
# ./spec/models/build_spec.rb:3:in `<top (required)>'
No examples found.
I am running rails version 6.1.4.1. I also know that my model exists as I can create new objects that belong to that table in the ruby console.
here is my rspec file (spec/models/build_spec.rb)
require 'spec_helper'
RSpec.describe Build, type: :model do
it "Has a name"
it "is not valid without name"
it "is not valid with too short name"
it "is not valid with too long of a name"
end
here is my gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.4'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4', '>= 6.1.4.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
gem 'will_paginate', '~> 3.3'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false
group :development, :test do
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4.2'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 3.26'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
gem 'rspec-rails', '>= 3.9.0'
end
group :production do
gem 'pg', '~> 1.1'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

spec_helper does not load the environment (this includes not loading the models). You could either require the model file explicitly in this spec or require rails_helper instead.

Check you have the right model inside the app/models/ directory.
spec/models/build_spec.rb
require 'rails_helper'
RSpec.describe Build, type: :model do
it { expect(described_class.new).to be_a() }
end
app/models/build.rb
class Build < ApplicationRecord
end
Hope this works for you.

Related

NameError: uninitialized constant ApplicationRecord despite having the application_record file correctly

I am having trouble using my actual models, I am getting the following error when trying to create a user:
app/models/user.rb:1:in `<top (required)>': uninitialized constant ApplicationRecord (NameError)
I do have the following file in models/application_record.rb
which looks like:
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
When I change the User class to inherit from ActiveRecord::Base instead, I get the same error, except for ActiveRecord.
My application.rb:
class Application < Rails::Application
config.load_defaults 6.1
config.generators.system_tests = nil
end
I am using Rails 6.1.
My Gemfile:
ruby '2.6.3'
gem 'activerecord'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', 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]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
gem 'listen', '~> 3.3'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
What is happening? I have no spelling mistakes, the model is user.rb, I can't figure out what's going on.
All of the advice I have found
So, if anyone is running into this problem, and you have the files you need, check to see if you're loading the rails environment. I added:
require "#{File.dirname(__FILE__)}/config/environment.rb"
to the top of the file I was running where I was calling the classes and that solved the problem.

Why can't I type in terminal after hitting binding.pry or byebug when running rails test?

When running the test suite for my Rails application, whenever I hit a binding.pry or byebug, my terminal gets corrupted-- what gets echoed to the terminal isn't what I'm typing and the only way to get things back to normal is to interrupt the process and run reset
Any ideas what the issue could be? I'm not sure where to start.
Here's my Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'rails', '6.0.2.1'
gem 'puma', '3.12.2'
gem 'sass-rails', '5.1.0'
gem 'webpacker', '4.0.7'
gem 'turbolinks', '5.2.0'
gem 'jbuilder', '2.9.1'
gem 'bootsnap', '1.4.5', require: false
gem 'bootstrap-sass', '3.4.1'
gem 'pry'
gem 'pry-rails'
gem 'bcrypt', '3.1.13'
group :development, :test do
gem 'sqlite3', '1.4.1'
gem 'byebug', '11.0.1', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'web-console', '4.0.1'
gem 'listen', '3.1.5'
gem 'spring', '2.1.0'
gem 'spring-watcher-listen', '2.0.1'
end
group :test do
gem 'capybara', '3.28.0'
gem 'selenium-webdriver', '3.142.4'
gem 'webdrivers', '4.1.2'
gem 'rails-controller-testing', '1.0.4'
gem 'minitest', '5.11.3'
gem 'minitest-reporters', '1.3.8'
gem 'guard', '2.15.0'
gem 'guard-minitest', '2.4.6'
end
group :production do
gem 'pg', '1.1.4'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
# source 'https://rubygems.org'
# git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# ruby '2.7.1'
# # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
# gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
# # Use sqlite3 as the database for Active Record
# gem 'sqlite3', '~> 1.4'
# # Use Puma as the app server
# gem 'puma', '~> 4.1'
# # Use SCSS for stylesheets
# gem 'sass-rails', '>= 6'
# # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
# gem 'webpacker', '~> 4.0'
# # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
# gem 'turbolinks', '~> 5'
# # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.7'
# # Use Redis adapter to run Action Cable in production
# # gem 'redis', '~> 4.0'
# # Use Active Model has_secure_password
# # gem 'bcrypt', '~> 3.1.7'
# # Use Active Storage variant
# # gem 'image_processing', '~> 1.2'
# # Reduces boot times through caching; required in config/boot.rb
# gem 'bootsnap', '>= 1.4.2', 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]
# 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.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'
# end
# group :test do
# # Adds support for Capybara system testing and selenium driver
# gem 'capybara', '>= 2.15'
# gem 'selenium-webdriver'
# # Easy installation and use of web drivers to run system tests with browsers
# gem 'webdrivers'
# end
# # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
# gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
I'm experiencing a very similar problem; my terminal output is inconsistent, repeated, and I can't type when I hit a breakpoint.
TLDR: Rails 6 added (by default) parallelized tests. These seem to trigger byebug breakpoints simultaneously in different worker processes. To fix, disable parallel tests.
This seems to be a known issue.
To fix, I simply commented out the indicated line in test_helper.rb that enables running tests in parallel:
# test/test_helper.rb
class ActiveSupport::TestCase
# ...
# comment out this line:
# parallelize(workers: :number_of_processors)
# ...
end
Notes
I noticed that the issue was connected to parallel testing since when the breakpoint triggered I saw my breakpoint and the surrounding code repeated 4 times (with the prompt (byebug) repeated three times, too:
This didn't start until I updated to Rails 6.1. I wasn't having this issue with Rails 6.0 for some reason.
I encountered the same issue using pry on github.com/rails/rails which does not have a test/test_helper.rb as referenced in Matt's response.
The issue was resolved by:
Run tests in serial by setting PARALLEL_WORKERS=1. Example
Run a single test with -n test_long_test_name. Example

imgkit gem not working on heroku in rails application

Hi I have a little application that is using imgkit to generate a png from some text. Every quote in my quote model uses imgkit to create a png version
app/controllers/quotes_controller.rb
def show
respond_to do |format|
format .html
format.png do
kit = IMGKit.new render_to_string, width: 1080, height: 1080
send_data kit.to_png, type: "image/png", disposition: "inline"
end
end
end
It works well on my local machine but when i upload to heroku imgkit stops working.
I tried adding the binaries to the gem file as below:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.3'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
gem 'bootstrap'
gem 'jquery-rails'
gem 'imgkit'
gem 'wkhtmltoimage-binary'
gem 'devise'
gem "font-awesome-rails"
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
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
gem 'bootsnap', '>= 1.1.0', 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 "better_errors"
gem "binding_of_caller"
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'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Unfortunately this didn't work.
I then followed the instructions at https://github.com/csquared/IMGKit#heroku
and downloaded the 10.0 version mentioned from https://github.com/wkhtmltopdf/obsolete-downloads/blob/master/README.md#linux
I added the file to bin/wkhtmltoimage-amd64 and I added the file config/initializers/imgkit.rb
with the following code to that file
IMGKit.configure do |config|
config.wkhtmltoimage = Rails.root.join('bin', 'wkhtmltoimage-amd64').to_s if ENV['RACK_ENV'] == 'production'
end
I tested and found it didnt work and I keep getting the
IMGKit::NoExecutableError (No wkhtmltoimage executable found at /app/bin/wkhtmltoimage-amd64
can anyone point me in the right direction, please let me know if you need any more info
You have added the binary at app/bin/wkhtmltoimage-amd64, but you're specifying Rails.root.join('bin', 'wkhtmltoimage-amd64'), which is bin/wkhtmltoimage-amd64.
Either
move the binary to bin/wkhtmltoimage-amd64, or
change Rails.root.join('bin', 'wkhtmltoimage-amd64') to Rails.root.join('app', 'bin', 'wkhtmltoimage-amd64').
I'd recommend the first option as it is more typical to have binaries at the root in bin/.

Rails Print Cups

In my rails app I am priting receipt using cups with gem cupsffi
This is the job I have set:
class PrintReceiptJob < ActiveJob::Base
require 'cupsffi'
printers = CupsPrinter.get_all_printer_names
printer = CupsPrinter.new(printers.first)
job = printer.print_file(Rails.root.join('receipt.pdf').to_s, {'PageSize' => 'A4'})
end
In my controller I generate the receipt in pdf with prawn and call the job above:
pdf = ReceiptPdf.new(#receipt)
pdf.render_file "receipt.pdf"
PrintReceiptJob.perform_now
And it works, the receipt gets printed.
Problem is, after printing I get this error:
[ActiveJob] [PrintReceiptJob] [044c6b97-daca-445d-9c87-631e3de3d7cd] Performing PrintReceiptJob (Job ID: 044c6b97-daca-445d-9c87-631e3de3d7cd) from Async(default)
[ActiveJob] [PrintReceiptJob] [044c6b97-daca-445d-9c87-631e3de3d7cd] Error performing PrintReceiptJob (Job ID: 044c6b97-daca-445d-9c87-631e3de3d7cd) from Async(default) in 0.52ms: NotImplementedError (NotImplementedError):
For what I understand it's trying to perform the job twice, and second time it fails.
application.rb
require_relative 'boot'
require 'apartment/elevators/subdomain'
require 'rails/all'
require File.expand_path('../boot', __FILE__)
ENV['RANSACK_FORM_BUILDER'] = '::SimpleForm::FormBuilder'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module CompanyManagement
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
config.time_zone = "Singapore"
end
end
Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
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
gem 'bootsnap', '>= 1.1.0', require: false
gem 'devise'
gem 'bootstrap'
gem 'jquery-ui-rails'
gem 'jquery-rails'
gem 'simple_form'
gem "font-awesome-rails"
gem "cocoon"
gem "select2-rails"
gem 'will_paginate'
gem 'will_paginate-bootstrap4'
gem "chartkick"
gem 'groupdate'
gem 'trix-rails', require: 'trix'
gem 'amoeba'
gem "simple_calendar", "~> 2.0"
gem 'apartment'
gem 'protokoll'
gem 'ransack'
gem "time_splitter"
gem 'working_hours'
gem 'jquery-minicolors-rails'
gem 'carrierwave', '~> 1.0'
gem 'prawn-rails'
gem 'cupsffi'
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]
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 'pry'
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'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
What am I missing? How can I fix?
You forgot to wrap your code with method:
require 'cupsffi'
class PrintReceiptJob < ActiveJob::Base
def perform
printers = CupsPrinter.get_all_printer_names
printer = CupsPrinter.new(printers.first)
job = printer.print_file(Rails.root.join('receipt.pdf').to_s, {'PageSize' => 'A4'})
end
end

Unable to autoload constant ActiveStorage::Blob::Analyzable

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.
Do you have config.active_storage.service = :amazon set in your development.rb by any chance?
I was getting the above error and it ended up being because I had the above line but the AWS env vars weren't set.
Make sure you check that all of the environment variables present:
AWS access key
AWS secret key
Bucket Name
checking spelling of the environment variables to make sure they match your storage.yml configuration file

Resources