将二维码生成改为图片显示

This commit is contained in:
yafeilee 2014-04-02 12:45:29 +08:00
parent 3486e055a9
commit d0fe2e350b
5 changed files with 21 additions and 3 deletions

View File

@ -27,6 +27,7 @@ gem 'nokogiri'
gem 'angularjs-rails'
gem 'figaro'
gem 'rqrcode-with-patches', require: 'rqrcode'
gem 'chunky_png'
gem 'sidekiq'
gem 'rest-client'

View File

@ -258,6 +258,7 @@ DEPENDENCIES
angularjs-rails
capybara
carrierwave-mongoid
chunky_png
coffee-rails (~> 4.0.1)
database_cleaner
factory_girl_rails

View File

@ -0,0 +1,16 @@
class QrcodesController < ApplicationController
def show
str = params[:str].to_s
max_length = 50
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

View File

@ -1,4 +1,3 @@
.qrcode-image
- qr = RQRCode::QRCode.new(str)
== qr.as_html
= image_tag( qrcodes_path(str: str) )
p 使用手机继续阅读 or 帮我分享至微信朋友圈

View File

@ -16,7 +16,8 @@ WBlog::Application.routes.draw do
resources :archives
# photos
resources :photos, :only=>[:create]
resources :photos, only: [:create]
get '/qrcodes' => 'qrcodes#show'
namespace :admin do
resources :posts do