2014-04-02 12:45:29 +08:00
|
|
|
class QrcodesController < ApplicationController
|
|
|
|
def show
|
|
|
|
str = params[:str].to_s
|
2014-04-02 13:37:02 +08:00
|
|
|
max_length = 200
|
2014-04-02 12:45:29 +08:00
|
|
|
if str.length > max_length
|
|
|
|
render nothing: true, status: 404
|
|
|
|
return
|
|
|
|
end
|
|
|
|
require 'rqrcode/export/png'
|
|
|
|
qr = RQRCode::QRCode.new(str)
|
|
|
|
response.headers['Cache-Control'] = "public, max-age=#{12.hours.to_i}"
|
|
|
|
response.headers['Content-Type'] = 'image/png'
|
|
|
|
response.headers['Content-Disposition'] = 'inline'
|
|
|
|
render :text => qr.as_png
|
|
|
|
end
|
|
|
|
end
|