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
Related
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/.
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
Getting a funky error when trying to run my Rails server.
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (~> 5.2, >= 5.2.1)
trix (~> 0.11.1) was resolved to 0.11.1, which depends on
rails (> 4.1, < 5.2)
I tried checking if it was an issue with the version in my Gemfile and make sure it's the latest, but this didn't help. Also tried installing trix by itself, and updating my version of Ruby, but no luck. Any tips on how to move from here?
This is my 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', '>= 5.2.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# 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'
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]
gem 'devise'
gem 'bulma-rails'
gem 'simple_form'
gem 'sidekiq'
gem 'carrierwave', '~> 1.0'
gem 'mini_magick', '~> 4.8'
gem 'stripe', '~> 3.11'
gem 'trix', '~> 0.11.1'
group :development, :test do
gem 'better_errors'
gem 'guard'
gem 'guard-livereload'
end
Appreciate any help. Thanks!
I have build my new rails application and when I am trying to deploy to Apache server while executing bundle exec rake secret I am getting rake aborted! cannot load such file -- ap.This is the URL I have referred to deploy Deploying a Ruby app on a Linux/Unix production server.
Please look into my Gemfile
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.4'
# Use sqlite3 as the database for Active Record
gem 'mysql2'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# 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 'therubyracer', 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', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'jquery-rails'
gem 'json'
gem 'jenkins_api_client'
gem 'mailfactory'
gem 'docx','>=0.2.07'
# gem 'jquery-turbolinks'
gem 'net-scp'
gem 'rubyXL'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'bcrypt'
# font awsome
gem "font-awesome-rails"
# parsley validation
gem "parsley-rails"
# devise for athentication
gem 'devise'
# gem "devise_ldap_authenticatable"
gem "toastr-rails"
# datapciker
gem 'bootstrap-datepicker-rails'
# image uploader
gem 'carrierwave'
# Active admin for admin
# gem 'activeadmin'
# To set dynamic value in docx
gem 'sablon'
# State_machine for status
gem 'aasm'
# Soft delete
gem 'paranoia'
# for seed
gem 'seed-fu'
# Net-SSH gem to exec batch file.
gem 'net-ssh'
# Schedule job
gem 'whenever', 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]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
end
group :development do
# Access an IRB console on exception pages or by using <%= 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'
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
gem "awesome_print", require:"ap"
# gem 'quiet_assets'
gem 'pry-rails'
gem 'bullet'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
This is my first application i tried to deploy, please help to resolve this issue
My ruby version is
ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-linux]
rails version - 5.1.4
This line in the Gemfile seems strange to me
gem "awesome_print", require:"ap"
Can you remove the require: "ap" and check if it works then?
so for all this while i have been deploying my web app without knowing its on production or not.
I would usually create my project as usual , where i just do the basic bundle install. and add new gems. Setup unicorn + nginx .
And then when i view the aws's public dns, it would show me my site as i would get on localhost:3000.
In my mind, i am still in development environment. However, it seems that when i installed a new gem , it only works on localhost:3000 but on the deployed site it self it is unrecognized. Example would be an ActiveAdmin gem , where on my site it shows "uninitialized constant ActiveAdmin" .
How should i solve this ? I am suspecting it could be because of different environments, but i am unsure how to approach this.
UPDATE my gem file
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# 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 'therubyracer', 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', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
#gem 'pdf-reader'
gem 'pdf-reader-turtletext'
gem 'nokogiri'
gem 'whenever', :require => false
gem 'unicorn'
gem 'devise'
#gem 'rails_admin', '~> 1.1.1'
gem 'activeadmin', github: 'activeadmin'
gem 'inherited_resources', github: 'activeadmin/inherited_resources'
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]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
end
group :development do
# Access an IRB console on exception pages or by using <%= 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
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]