不能写未知属性`info'PrawnPDF [英] can't write unknown attribute `info' PrawnPDF

查看:85
本文介绍了不能写未知属性`info'PrawnPDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Prawn PDF即时生成发票PDF,但我不断收到错误消息无法写入未知属性'info'",但在任何情况下我都没有属性'info'有关的数据库表(或与此有关的我的整个数据库).我不知道这是我所缺少的宝石.这是我正在关注的教程: http://www.idyllic-software.com/blog/creating-pdf-using-prawn-in-ruby-on-rails/

I'm using Prawn PDF to generate an invoice PDF on the fly and I keep getting the error "can't write unknown attribute 'info'" but I don't have an attribute 'info' anywhere in any of the concerned database tables (or my entire database for that matter). I don't know if it's something in the gem that I'm missing. Here is the tutorial I'm following: http://www.idyllic-software.com/blog/creating-pdf-using-prawn-in-ruby-on-rails/ and http://www.sitepoint.com/pdf-generation-rails/

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

I did register the mime type in the initializer (didn't show bc it's so simple, but I can if that's needed)

我还多次重新启动服务器,以确保这不是问题.

I also restarted the server multiple times to make sure that wasn't the issue.

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

I know the gem is installed properly because I can generate an empty PDF no problem, but when I try to add in @invoice is when I run into the issue.

发票显示控制器操作:

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

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'

推荐答案

仍然不知道问题出在哪里,但安装时一定有毛病.我重新设置了对虾的整个设置,现在可以正常工作了……没什么不同.

Still have no idea what the problem was, but it must've had a glitch on the install. I redid the whole setup for prawn and it works now...nothing else different.

这篇关于不能写未知属性`info'PrawnPDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆