36
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RailsでQRコードを表示するのがとても簡単だった(rqrcode)

Last updated at Posted at 2015-09-19

RailsでQRコードを表示するのがとても簡単だった(rqrcode)

gemを追加します。

Gemfile
gem 'rqrcode'

application helperにqrcode_tagメソッドを追加します。

app/helpers/application_helper.rb
module ApplicationHelper
  def qrcode_tag(text, options = {})
    ::RQRCode::QRCode.new(text).as_svg(options).html_safe
  end
end

viewで表示します。

<%= qrcode_tag request.url, module_size: 5 %>

完成

svg形式で表示していますが、
as_svgの所を他の形式に変えればsvgに未対応のブラウザでも表示させるようにもできます。

36
32
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
36
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?