gpt4 book ai didi

ruby-on-rails - rails/Prawn : how do I use rails helpers inside a Prawn class?

转载 作者:数据小太阳 更新时间:2023-10-29 06:55:36 33 4
gpt4 key购买 nike

我正在尝试在 prawn 类中使用 rails 3.2 助手,但 rails 抛出:

undefined method `number_with_precision' for #<QuotePdf:0x83d4188>

Prawn 类

class QuotePdf < Prawn::Document
def initialize(quote)
super()

text "sum: #{number_with_precision(quote.sum)}"
end
end

Controller

def show
@quote = current_user.company.quotes.where(:id => params[:id]).first
head :unauthorized and return unless @quote

respond_with @quote, :layout => !params[:_pjax] do |format|
format.pdf do
send_data QuotePdf.new(@quote).render, filename: "Devis-#{@quote.date_emission.strftime("%d/%m/%Y")}.pdf",
type: "application/pdf"
end
end
end

感谢您的帮助。

最佳答案

您必须在您的 prawn 文档类中明确包含 ActionView::Helpers::NumberHelper(或任何其他辅助类/模块)。

class QuotePdf < Prawn::Document
include ActionView::Helpers::NumberHelper # <-

def initialize(quote)
super()

text "sum: #{number_with_precision(quote.sum)}"
end
end

关于ruby-on-rails - rails/Prawn : how do I use rails helpers inside a Prawn class?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9708884/

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