【问题标题】:How to display boolean field in prawn pdf?如何在对虾pdf中显示布尔字段?
【发布时间】:2013-01-09 06:02:41
【问题描述】:

我正在尝试使用 pawn 在表中显示布尔字段。我收到以下错误:

Content type not recognized: false

我已经阅读了http://prawn.majesticseacreature.com/manual.pdf 和 rdoc,但找不到答案。

这是简单的表格布局:

  def data
     table [["Design Type", @design.design_type],
            ["Hole Punch", @design.hole_punch]]
  end

【问题讨论】:

    标签: ruby-on-rails-3.2 pdf-generation prawn


    【解决方案1】:

    事实上,任何类型的变量都会遇到同样的问题,而不仅仅是布尔值。 要获取变量的内容,您需要将它放在这样的字符串中:

    table [["Design Type", "#{@design.design_type}"],
           ["Hole Punch", "#{@design.hole_punch}"]]
    

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      另一种选择是将布尔值转换为字符串:

        def data
           table [["Design Type", @design.design_type.to_s],
                  ["Hole Punch", @design.hole_punch.to_s]]
        end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-23
        相关资源
        最近更新 更多