[Vuejs]-Ruby on Rails Add Text to QR Code Image Generated by RQRCODE_PNG

0๐Ÿ‘

I had a similar requirement for my app. I ended up making a view for the combined QR code + text. If you need to display it within another page, you can render it as a partial.

For example, I wanted a QR code that loads a reply form to a survey:

SurveysController

def qr
  @survey = Survey.find(params[:id])
end

def qr_image
  qr = RQRCode::QRCode.new new_reply_url(slug: params[:id])
  respond_to do |format|
    format.png { send_data qr.as_png(size: 640), type: 'image/png', disposition: 'inline' }
    format.html { render html: qr.as_html.html_safe }
  end
end

surveys/qr.html.erb

In my case I wanted to display the name of a survey above the QR code.

<div class="row text-center">
  <h3 class="col-sm-12 "><%= @survey.name %></h3>

  <div class="col-sm-12 ">
    <%= image_tag qr_image_path(@survey) + ".png" %>
  </div>
</div>
๐Ÿ‘คJacob Vanus

Leave a comment