【发布时间】:2014-08-17 19:04:58
【问题描述】:
使用 qrcode 创建 Ruby on Rails Web 应用程序,在 pdf 中显示 QR 码
我正在使用
gem 'rqrcode-with-patches', require: 'rqrcode'
gem 'prawn'
我的帖子控制器显示 pdf 视图
def show
@qr=RQRCode::QRCode.new(request.url)
respond_to do |format|
format.html
format.pdf do
pdf = PostPdf.new(@post)
send_data pdf.render, filename: "post#{@post.id}.pdf",
type: "application/pdf",
disposition: "inline"
end
end
end
post_pdf
class PostPdf < Prawn::Document
def initialize(post)
super({top_margin: 30, page_size: 'A4', page_layout: :landscape })
@post = post
post_id
post_title
qr_code
end
def post_id
move_down 10
text "Post id: #{@post.id}"
end
def post_title
move_down 10
text "Post title: #{@post.title}"
end
def qr_code
move_down 10
@qr=RQRCode::QRCode.new(request.url)
end
end
我在显示 pdf 时遇到错误,它是显示
未定义的局部变量或方法“请求”#
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 qr-code prawn