2015-02-23 83 views
3

我采用了Railscast第153集修订版的方法。
我控制器未初始化的常量Prawn :: FLOAT_PRECISION在使用对象时显示的错误

class AdminsController < ApplicationController 

    def index  
    @examples = Example.all 
    respond_to do |format| 
     format.html 
     format.csv { send_data @examples.to_csv } 
     format.xls { send_data @examples.to_csv } 
     format.pdf do 
     pdf = DownloadPdf.new(@examples) 
     send_data pdf.render, filename: 'generate_table.pdf', 
      type: 'application/pdf', disposition: "inline" 
     end 
    end 
    end 
end 

和我download_pdf.rb文件

class DownloadPdf < Prawn::Document#make_table 

    require 'prawn/table' 
    def initialize(example) 
    super() 
     @examples = example 
     line_items 
    end 

    def line_items 

    image "#{Rails.root}/app/assets/images/logo.png"  
    table [[1,2],[3,4]] 
    end 
end 

我使用宝石

gem 'prawn', :git => "https://github.com/prawnpdf/prawn.git", :ref => '8028ca0cd2' 
gem 'prawn-table', '~> 0.1.0' 

Thanx提前帮助。

回答

1

TL; DRgem 'prawn'和运行bundle install:加入给你的Gemfile中更新prawn宝石。

再回应:您使用的是旧版本的大虾 - 这ref您正在使用您的Gemfile是指介于2013年prawn-table 0.1是新的,需要的prawn新版本。更确切地说,它使用的是Prawn::FLOAT_PRECISION常数,它被添加到this 2014's commitPrawn

+1

非常感谢,它的工作 – 2015-02-23 08:55:56

+0

太好了!不要忘了标记答案已被接受/ upvote,如果它帮助你。 – dgilperez 2015-02-23 08:57:34

0

请Gemfile中

下面使用
gem 'prawn' 

然后取出Gemfile.lock

然后

bundle install

重启服务器

+0

这是如何添加到我的答案? – dgilperez 2015-02-23 08:56:40

+0

我没有看到你的答案投票了你的答案 – 2015-02-23 09:00:02

0

可以使用round(2)这样的..

val= 456.7890999999 
val.round(2) 

和答案将是456.79

相关问题