编程新手,这是我的第二个问题。prawn-qrcode 看起来像我的解决方案,但安装说明对于代码的位置有点模糊。感谢这里的帮助,我的代码中可能存在一些错误。
**Gem File**
gem 'devise'
gem 'linkedin'
gem 'omniauth'
gem 'omniauth-linkedin'
gem 'haml'
gem 'carrierwave'
gem 'rmagick'
gem 'rqrcode', "~> 0.4.2"
gem 'prawn-qrcode', "~> 0.2.0"
gem 'will_paginate', '> 3.0'
gem 'ransack'
gem 'omniauth-google-oauth2'
gem 'prawn'
gem 'hirb'
Relevant section of the controller
def show
@property = Property.find(params[:id])
@qr = RQRCode::QRCode.new(property_path, :size => 6, :level => :h )
@prospect = Prospect.new
respond_to do |format|
format.html # show.html.erb
format.json { render json: @property }
format.pdf do
pdf = PropertyPdf.new(@property)
send_data pdf.render, type: "application/pdf",
disposition: "inline"
end
end
end
Prawn PDF View
class PropertyPdf < Prawn::Document
def initialize(property)
super(top_margin: 70)
@property = property
@qrcode_content = 'http://tbd.com'
qrcode
building_heading
end
def qrcode
print_qr_code(@qrcode_content, :dot=>2.8)
end
谢谢