【问题标题】:Invalid encoding with rqrcoderqrcode 编码无效
【发布时间】:2014-08-09 21:06:32
【问题描述】:

我遇到了无效的编码错误,无法将图像保存到载波上传器。

require 'rqrcode_png'
img = RQRCode::QRCode.new( 'test', :size => 4, :level => :h ).to_img.to_s

img.valid_encoding? 

=> false

【问题讨论】:

    标签: ruby-on-rails carrierwave qr-code


    【解决方案1】:

    我不确定这是否是您要查找的内容,在我的情况下,我需要使用carrierwave 将生成的二维码与Rails 模型相关联,我最终将图像保存到临时文件中,将该文件与模型相关联,然后删除临时文件,这是我的代码:

    def generate_qr_code!
      tmp_path = Rails.root.join('tmp', "some-filename.png")
      tmp_file = RQRCode::QRCode.new(self.hash_value).to_img.resize(200,200).save(tmp_path)
    
      # Stream is handed closed, we need to reopen it
      File.open(tmp_file.path) do |file|
        self.qr_code = file
      end
    
      File.delete(tmp_file.path)
    
      self.save!
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-04
      • 2010-12-19
      • 2019-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多