Sha256: 9c07cd4112a1ce9c9a22ed294f212f5d48e3b61bea37a871ed145904def0956c

Contents?: true

Size: 892 Bytes

Versions: 3

Compression:

Stored size: 892 Bytes

Contents

module QrcodeHelper
  def qrcode(data = '', options = {})
    # Google API: https://google-developers.appspot.com/chart/infographics/docs/qr_codes
    width                  = options.delete(:width) { '200' }
    output_encoding        = options.delete(:output_encoding)
    error_correction_level = options.delete(:error_correction_level)
    margin                 = options.delete(:margin)

    qrcode_url = 'https://chart.googleapis.com/chart?cht=qr'
    qrcode_url += "&chl=#{data}"
    qrcode_url += "&chs=#{width}x#{width}"
    qrcode_url += "&choe=#{output_encoding}" if output_encoding
    if error_correction_level && margin
      qrcode_url += "&chld=#{error_correction_level}|#{margin}"
    else
      qrcode_url += "&chld=#{error_correction_level}" if error_correction_level
      qrcode_url += "&chld=|#{margin}" if margin
    end
    image_tag(qrcode_url, alt: data)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
andy_rails_toolbox-1.3.0 app/helpers/qrcode_helper.rb
andy_rails_toolbox-1.2.1 app/helpers/qrcode_helper.rb
andy_rails_toolbox-1.2.0 app/helpers/qrcode_helper.rb