Ruby generates a two-dimensional code using RQRCODE

Reference: https://github.com/whomwah/rqrcode

1. gem’rqrcode’

2. In the helper:

< pre class="hljs ruby"> 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 Base 64.encode64 png return “data:image/png;base64,#{Base64.encode64(png)}” end < /span>

3, views page

3. p>

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

Leave a Comment

Your email address will not be published.