gpt4 book ai didi

ruby-on-rails - 使用 Ruby on rails 渲染 Prawn pdf 和 rqrcode 显示 QR

转载 作者:太空宇宙 更新时间:2023-11-03 16:49:39 24 4
gpt4 key购买 nike

创建带有二维码的Ruby on Rails web应用程序,在pdf中显示二维码

我正在使用

gem 'rqrcode-with-patches', require: 'rqrcode'
gem 'prawn'

我的帖子 Controller 显示 pdf View

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 时出错,正在显示

undefined local variable or method `request' for #

最佳答案

有一个名为 prawn-qrcodes 的 gem它真的是单一使用。

require 'prawn/qrcodes'

Prawn::Document.generate("qr-big.pdf") do
msg = "Hello world, this is a QR code"
text msg

qrcode msg, :position => :center,
:fit => [bounds.height, bounds.width]
end

我认为这比 ** rqrcode-with-patches** 更适合您,因为它是为 prawn

构建的

关于ruby-on-rails - 使用 Ruby on rails 渲染 Prawn pdf 和 rqrcode 显示 QR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25352657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com