码迷,mamicode.com
首页 > 其他好文 > 详细

ruby 使用 rqrcode 生成二维码

时间:2019-09-26 19:54:59      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:git   bst   span   false   cti   const   function   ack   word   

参考:  https://github.com/whomwah/rqrcode

1.  gem ‘rqrcode‘

2.  在helper中: 

 require ‘base64‘
  def generate_qr_code string
    qr_code = RQRCode::QRCode.new string
    png = qr_code.as_png(
      resize_gte_to: false,
      resize_exactly_to: false,
      fill: ‘white‘,
      color: ‘black‘,
      size: 180,
      border_modules: 0,
      module_px_size: 0,
      file: nil # path to write
    ).to_s
    Base64.encode64 png
    return "data:image/png;base64,#{Base64.encode64(png)}"
  end 

3、views页面

<%= image_tag generate_qr_code(‘http://baidu.com‘)%>

ruby 使用 rqrcode 生成二维码

标签:git   bst   span   false   cti   const   function   ack   word   

原文地址:https://www.cnblogs.com/lv-books/p/11593901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!