Unable to autoload constant ActiveStorage::Blob::Analyzable - ruby-on-rails

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

Related

Rails Error: Sprockets::FileNotFound in Users::Sessions#new

The following error occurred while executing the project after git clone, yarn install and bundle install.
Error logs
Sprockets::FileNotFound in Users::Sessions#new
Showing /Users/{...}/Desktop/{my_project_dir}/app/views/users/sessions/new.html.erb where line #9 raised:
couldn't find file 'angular/1.8.0/angular' with type 'application/javascript'
Checked in these paths:
/Users/{...}/{my_project_dir}/app/assets/config
/Users/{...}/{my_project_dir}/app/assets/fonts
/Users/{...}/{my_project_dir}/app/assets/images
/Users/{...}/{my_project_dir}/app/assets/javascripts
/Users/{...}/{my_project_dir}/app/assets/stylesheets
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/app/assets/images
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/app/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/app/assets/stylesheets
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/vendor/assets/fonts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/vendor/assets/images
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/vendor/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rails_admin-2.0.2/vendor/assets/stylesheets
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/remotipart-1.4.4/vendor/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/nested_form-0.3.2/vendor/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/jquery-ui-rails-6.0.1/app/assets/images
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/jquery-ui-rails-6.0.1/app/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/jquery-ui-rails-6.0.1/app/assets/stylesheets
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/jquery-rails-4.4.0/vendor/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/apidoco-1.6.2/app/assets/config
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/apidoco-1.6.2/app/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/apidoco-1.6.2/app/assets/stylesheets
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/coffee-rails-4.2.2/lib/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actioncable-6.0.3.4/app/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activestorage-6.0.3.4/app/assets/javascripts
/Users/{...}/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionview-6.0.3.4/lib/assets/compiled
/Users/{...}/{my_project_dir}/node_modules):
6:
7: <div class="text-center w-75 m-auto">
8: <a href="/">
9: <span><img src="<%= image_url('bi.png') %>" alt="" height="50" /></span>
10: </a>
11: <p class="text-muted mt-3"> Title description </p><p class="text-muted"></p>
12: </div>
I don't understand why couldn't find file 'angular/1.8.0/angular' with type 'application/javascript' is happened.
Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.0'
# 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 '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 Active Storage variant
gem 'image_processing', '~> 1.2'
# Json Serializer
gem 'fast_jsonapi'
# api docs
gem 'apidoco'
# admin
gem 'rails_admin', '~> 2.0'
# control cors
gem 'rack-cors'
# pagination
gem 'kaminari'
gem 'will_paginate', '~> 3.1.0'
# api call
gem 'rest-client'
# user and admin
gem 'devise'
gem 'devise-jwt'
gem 'omniauth-oauth2'
gem 'omniauth-google-oauth2'
gem 'omniauth-naver'
gem 'devise-i18n'
# manage role
gem 'cancancan'
gem 'rolify'
# active storage
gem 'active_storage_validations'
gem 'aws-sdk-s3'
# Use ActiveStorage variant
gem 'mini_magick', '~> 4.8'
# Scheduled Job
gem 'whenever'
# Active Job
gem 'sidekiq'
gem 'connection_pool'
gem 'redis-namespace'
# 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]
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]
First of all I haven't written any angular related code within the project.
i've tried
I deleted the error code and tried again, but the same problem occurs with other erb code.
I thought maybe it could be a version of the gem files. After deleting all gems, I reinstalled ruby (using rbenv), but I got the same error.
I have installed angular#1.8.0, but I got the same error.
Please let me know solution about couldn't find file 'angular/1.8.0/angular' with type 'application/javascript'
I found problem that since multiple projects are running on one server, all the projects have to be loaded locally. In the process, there was a conflict with the apidoco gem.
Solution is to remove apidoco from the Gemfile of the problem project.

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

Your Ruby version is 2.5.1, but your Gemfile specified 2.6.3

I'm trying to run command " rake db:test:prepare" in 6.2 of Rails Tutorial book. And then I had this problem
I have already run " gem install bundler". But it wasn't work. After I check version in path /home/myname/.rvm/gems. T got version of Ruby is 2.6.3
Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.3'
# 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
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 'annotate', '~> 2.7', '>= 2.7.5'
gem 'rspec-rails', '~> 3.8', '>= 3.8.2'
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]
# group :production do
# gem 'pg', '0.17.1'
# gem 'rails_12factor', '0.0.2'
# end
How can i fix this problem? Thank you.
This usually comes up when the specified ruby version is not installed. To install using rvm run:
rvm install ruby-2.6.3
If you suspect it's already installed, then you may need to tell rvm to use the specific version, as it might default to another version (in this case 2.5.1). To do that run:
rvm --default use ruby-2.6.3
If it's not installed, the above command will throw a relevant error.

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

Resources