参考: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
参考: 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‘)%>