导轨打印杯

问题描述 投票:0回答:1

在我的rails应用程序中,我使用带有宝石qazxsw poi的杯子打印收据

这是我设定的工作:

cupsffi

在我的控制器中,我用pdf生成pdf收据并调用上面的工作:

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

它有效,收据打印出来。

问题是,打印后我得到这个错误:

pdf = ReceiptPdf.new(@receipt)
pdf.render_file "receipt.pdf"
PrintReceiptJob.perform_now

据我所知,它试图执行两次工作,第二次失败。

application.rb中

[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):

的Gemfile:

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

我错过了什么?我该怎么办?

ruby-on-rails cups
1个回答
0
投票

你忘了用方法包装你的代码:

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]
© www.soinside.com 2019 - 2024. All rights reserved.