rails项目生成二维码

Rails 项目中将连接生成二维码

准备

Gemfile中添加

1
gem 'rqrcode_png'
1
2
3
4
5
6
7
8
9
10
11
# 生成二维码
def print_rqrcode
html = ""
require 'rqrcode'
host = "https://www.baidu.com" # 链接地址
qr = RQRCode::QRCode.new(host, :size => 10, :level => :h )
html <<
"#{qr.as_svg(offset: 0, color: '000',
shape_rendering: 'crispEdges',
module_size: 2)}"
end