不能写未知属性`info'PrawnPDF

时间:2015-08-12 13:24:20

标签: ruby-on-rails pdf prawn

我正在使用Prawn PDF动态生成发票PDF并且我不断收到错误“无法写入未知属性'信息'”但我在任何地方都没有任何属性'info'有关数据库表(或我的整个数据库)。我不知道宝石中是否有我遗漏的东西。以下是我正在关注的教程:http://www.idyllic-software.com/blog/creating-pdf-using-prawn-in-ruby-on-rails/http://www.sitepoint.com/pdf-generation-rails/

我确实在初始化程序中注册了mime类型(没有显示bc它是如此简单,但我可以,如果需要的话)

我还多次重启服务器,以确保不是问题。

我知道gem已正确安装,因为我可以生成一个空的PDF没有问题,但当我尝试添加@invoice时,我遇到了问题。

发票显示控制器操作:

def show
    @invoice = Invoice.find(params[:id])
    @customer = @invoice.customer
    @user = current_user
    @company = @user.company

    respond_to do |format|
        format.html
        format.pdf do
            pdf = InvoicePdf.new(@invoice)
            send_data pdf.render, filename: "invoice_#{@invoice.created_at.strftime("%m/%d/%Y")}.pdf", type: "application/pdf"
        end
    end
end

InvoicePdf.rb

class InvoicePdf < Prawn::Document

    def intialize(invoice)
        super()
        @invoice = invoice
    end

    def header
        image "https://www.google.com/images/srpr/logo11w.png", width: 530, height: 150
    end

    def text_content
        y_position = cursor - 50

        bounding_box([0, y_position], :width => 270, :height => 300) do
          text "Lorem ipsum", size: 15, style: :bold
          text "Lorem ipsum dolor sit amet, consectetur adipiscing elit.  Suspendisse interdum semper placerat. Aenean mattis fringilla risus ut fermentum. Fusce posuere dictum venenatis. Aliquam id tincidunt ante, eu pretium eros. Sed eget risus a nisl aliquet scelerisque sit amet id nisi. Praesent porta molestie ipsum, ac commodo erat hendrerit nec. Nullam interdum ipsum a quam euismod, at consequat libero bibendum. Nam at nulla fermentum, congue lectus ut, pulvinar nisl. Curabitur consectetur quis libero id laoreet. Fusce dictum metus et orci pretium, vel imperdiet est viverra. Morbi vitae libero in tortor mattis commodo. Ut sodales libero erat, at gravida enim rhoncus ut."
        end

        bounding_box([300, y_position], :width => 270, :height => 300) do
          text "Duis vel", size: 15, style: :bold
          text "Duis vel tortor elementum, ultrices tortor vel, accumsan dui. Nullam in dolor rutrum, gravida turpis eu, vestibulum lectus. Pellentesque aliquet dignissim justo ut fringilla. Interdum et malesuada fames ac ante ipsum primis in faucibus. Ut venenatis massa non eros venenatis aliquet. Suspendisse potenti. Mauris sed tincidunt mauris, et vulputate risus. Aliquam eget nibh at erat dignissim aliquam non et risus. Fusce mattis neque id diam pulvinar, fermentum luctus enim porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos."
        end
    end

end

完整追踪:

    activerecord (4.1.0) lib/active_record/attribute_methods/write.rb:72:in `write_attribute'
    activerecord (4.1.0) lib/active_record/attribute_methods/dirty.rb:68:in `write_attribute'
    activerecord (4.1.0) lib/active_record/attribute_methods.rb:390:in `[]='
    pdf-core (0.6.0) lib/pdf/core/document_state.rb:42:in `normalize_metadata'
    pdf-core (0.6.0) lib/pdf/core/document_state.rb:5:in `initialize'
    prawn (2.0.2) lib/prawn/document.rb:200:in `new'
    prawn (2.0.2) lib/prawn/document.rb:200:in `initialize'
    app/controllers/invoices_controller.rb:23:in `new'
    app/controllers/invoices_controller.rb:23:in `block (2 levels) in show'
    actionpack (4.1.0) lib/action_controller/metal/mime_responds.rb:258:in `call'
    actionpack (4.1.0) lib/action_controller/metal/mime_responds.rb:258:in `respond_to'
    app/controllers/invoices_controller.rb:20:in `show'
    actionpack (4.1.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
    actionpack (4.1.0) lib/abstract_controller/base.rb:189:in `process_action'
    actionpack (4.1.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
    actionpack (4.1.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
    activesupport (4.1.0) lib/active_support/callbacks.rb:113:in `call'
    activesupport (4.1.0) lib/active_support/callbacks.rb:113:in `call'
    activesupport (4.1.0) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
    activesupport (4.1.0) lib/active_support/callbacks.rb:149:in `call'
    activesupport (4.1.0) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
    activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `call'
    activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `block in halting'
    activesupport (4.1.0) lib/active_support/callbacks.rb:149:in `call'
    activesupport (4.1.0) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
    activesupport (4.1.0) lib/active_support/callbacks.rb:229:in `call'
    activesupport (4.1.0) lib/active_support/callbacks.rb:229:in `block in halting'
    activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `call'
    activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `block in halting'
    activesupport (4.1.0) lib/active_support/callbacks.rb:86:in `call'
    activesupport (4.1.0) lib/active_support/callbacks.rb:86:in `run_callbacks'
    actionpack (4.1.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
    actionpack (4.1.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
    actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
    activesupport (4.1.0) lib/active_support/notifications.rb:159:in `block in instrument'
    activesupport (4.1.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    activesupport (4.1.0) lib/active_support/notifications.rb:159:in `instrument'
    actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
    actionpack (4.1.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
    activerecord (4.1.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
    actionpack (4.1.0) lib/abstract_controller/base.rb:136:in `process'
    actionview (4.1.0) lib/action_view/rendering.rb:30:in `process'
    actionpack (4.1.0) lib/action_controller/metal.rb:195:in `dispatch'
    actionpack (4.1.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
    actionpack (4.1.0) lib/action_controller/metal.rb:231:in `block in action'
    actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
    actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
    actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
    actionpack (4.1.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
    actionpack (4.1.0) lib/action_dispatch/journey/router.rb:59:in `each'
    actionpack (4.1.0) lib/action_dispatch/journey/router.rb:59:in `call'
    actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:676:in `call'
    omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
    omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
    warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
    warden (1.2.3) lib/warden/manager.rb:34:in `catch'
    warden (1.2.3) lib/warden/manager.rb:34:in `call'
    rack (1.5.2) lib/rack/etag.rb:23:in `call'
    rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
    rack (1.5.2) lib/rack/head.rb:11:in `call'
    actionpack (4.1.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
    actionpack (4.1.0) lib/action_dispatch/middleware/flash.rb:254:in `call'
    rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
    rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
    actionpack (4.1.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
    activerecord (4.1.0) lib/active_record/query_cache.rb:36:in `call'
    activerecord (4.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
    activerecord (4.1.0) lib/active_record/migration.rb:380:in `call'
    actionpack (4.1.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
    activesupport (4.1.0) lib/active_support/callbacks.rb:82:in `run_callbacks'
    actionpack (4.1.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
    actionpack (4.1.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
    actionpack (4.1.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
    better_errors (2.1.1) lib/better_errors/middleware.rb:59:in `call'
    actionpack (4.1.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
    actionpack (4.1.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
    railties (4.1.0) lib/rails/rack/logger.rb:38:in `call_app'
    railties (4.1.0) lib/rails/rack/logger.rb:20:in `block in call'
    activesupport (4.1.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
    activesupport (4.1.0) lib/active_support/tagged_logging.rb:26:in `tagged'
    activesupport (4.1.0) lib/active_support/tagged_logging.rb:68:in `tagged'
    railties (4.1.0) lib/rails/rack/logger.rb:20:in `call'
    actionpack (4.1.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
    rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
    rack (1.5.2) lib/rack/runtime.rb:17:in `call'
    activesupport (4.1.0) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
    rack (1.5.2) lib/rack/lock.rb:17:in `call'
    actionpack (4.1.0) lib/action_dispatch/middleware/static.rb:64:in `call'
    rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
    railties (4.1.0) lib/rails/engine.rb:514:in `call'
    railties (4.1.0) lib/rails/application.rb:144:in `call'
    rack (1.5.2) lib/rack/lock.rb:17:in `call'
    rack (1.5.2) lib/rack/content_length.rb:14:in `call'
    rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
    /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
    /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
    /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

1 个答案:

答案 0 :(得分:0)

仍然不知道问题是什么,但它必须在安装上出现故障。我重新整理了对虾的整个设置,它现在正常工作......没有别的不同。