Spree::Admin::Orders#show 中的类型错误 - 没有将 Sprockets::Asset 隐式转换为字符串

TypeError in Spree::Admin::Orders#show -no implicit conversion of Sprockets::Asset into String

我正在使用 spree_print_invoice gem on a spreecommerce project 中的 '3-0-stable (3.0.1)。

我的 gem 文件包含以下行,我使用 ruby 2.2.2

gem 'spree_print_invoice', github: 'spree-contrib/spree_print_invoice', branch: '3-0-stable'.

但是当我点击打印发票时,出现以下错误。

Started GET "/admin/orders/R987654321.pdf?template=invoice" for 127.0.0.1 at 2015-07-16 06:41:21 +0530
Processing by Spree::Admin::OrdersController#show as PDF
  Parameters: {"template"=>"invoice", "id"=>"R987654321"}
  Spree::Preference Load (0.8ms)  SELECT  "spree_preferences".* FROM "spree_preferences" WHERE "spree_preferences"."key" =  LIMIT 1  [["key", "spree/backend_configuration/locale"]]
  Spree::User Load (1.1ms)  SELECT  "spree_users".* FROM "spree_users" WHERE "spree_users"."deleted_at" IS NULL AND "spree_users"."id" =   ORDER BY "spree_users"."id" ASC LIMIT 1  [["id", 1]]
   (1.0ms)  SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" =  AND "spree_roles"."name" =   [["user_id", 1], ["name", "admin"]]
  Spree::Order Load (1.0ms)  SELECT  "spree_orders".* FROM "spree_orders" WHERE "spree_orders"."number" =   ORDER BY "spree_orders"."id" ASC LIMIT 1  [["number", "R987654321"]]
  Spree::Adjustment Load (1.0ms)  SELECT "spree_adjustments".* FROM "spree_adjustments" WHERE "spree_adjustments"."adjustable_type" = 'Spree::Order' AND "spree_adjustments"."adjustable_id" IN (2)  ORDER BY spree_adjustments.created_at ASC
  Spree::Preference Load (0.8ms)  SELECT  "spree_preferences".* FROM "spree_preferences" WHERE "spree_preferences"."key" =  LIMIT 1  [["key", "spree/print_invoice_setting/next_number"]]
  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/bundler/gems/spree_print_invoice-a4b8acfcaedf/app/views/spree/admin/orders/invoice.pdf.prawn (164.1ms)
Completed 500 Internal Server Error in 351ms (ActiveRecord: 5.7ms)

ActionView::Template::Error (no implicit conversion of Sprockets::Asset into String):
     9: 
    10:   if im && File.exist?(im.pathname)
    11:     image im, vposition: :top, height: 40, scale: Spree::PrintInvoice::Config[:logo_scale]
    12:   end
    13: 
    14:   grid([0,3], [0,4]).bounding_box do
    15:     font @font_face, size: @font_size
  prawn (1.0.0) lib/prawn/images.rb:144:in `initialize'
  prawn (1.0.0) lib/prawn/images.rb:144:in `new'
  prawn (1.0.0) lib/prawn/images.rb:144:in `verify_and_open_image'
  prawn (1.0.0) lib/prawn/images.rb:79:in `build_image_object'
  prawn (1.0.0) lib/prawn/images.rb:67:in `image'
  /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/bundler/gems/spree_print_invoice-a4b8acfcaedf/lib/prawn_handler.rb:30:in `method_missing'
  /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/bundler/gems/spree_print_invoice-a4b8acfcaedf/app/views/spree/admin/orders/invoice.pdf.prawn:12:in `block in _9de645c5feda03bf902dcb753ec0eb61'
  pdf-core (0.2.5) lib/pdf/core/page.rb:62:in `stamp_stream'
  prawn (1.0.0) lib/prawn/stamp.rb:83:in `create_stamp'
  prawn (1.0.0) lib/prawn/repeater.rb:99:in `initialize'
  prawn (1.0.0) lib/prawn/repeater.rb:79:in `new'
  prawn (1.0.0) lib/prawn/repeater.rb:79:in `repeat'
  /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/bundler/gems/spree_print_invoice-a4b8acfcaedf/lib/prawn_handler.rb:30:in `method_missing'
  /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/bundler/gems/spree_print_invoice-a4b8acfcaedf/app/views/spree/admin/orders/invoice.pdf.prawn:8:in `_9de645c5feda03bf902dcb753ec0eb61'
  actionview (4.2.2) lib/action_view/template.rb:145:in `block in render'
  activesupport (4.2.2) lib/active_support/notifications.rb:166:in `instrument'
  actionview (4.2.2) lib/action_view/template.rb:333:in `instrument'
  actionview (4.2.2) lib/action_view/template.rb:143:in `render'
  deface (1.0.1) lib/deface/action_view_extensions.rb:41:in `render'
  actionview (4.2.2) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
  actionview (4.2.2) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
  activesupport (4.2.2) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.2) lib/active_support/notifications.rb:164:in `instrument'
  actionview (4.2.2) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
  actionview (4.2.2) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
  actionview (4.2.2) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
  actionview (4.2.2) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
  actionview (4.2.2) lib/action_view/renderer/template_renderer.rb:14:in `render'
  actionview (4.2.2) lib/action_view/renderer/renderer.rb:42:in `render_template'
  actionview (4.2.2) lib/action_view/renderer/renderer.rb:23:in `render'
  actionview (4.2.2) lib/action_view/helpers/rendering_helper.rb:32:in `render'
  /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/bundler/gems/spree_print_invoice-a4b8acfcaedf/app/models/spree/order_decorator.rb:81:in `render_pdf'
  /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/bundler/gems/spree_print_invoice-a4b8acfcaedf/app/models/spree/order_decorator.rb:33:in `pdf_file'
  /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/bundler/gems/spree_print_invoice-a4b8acfcaedf/app/controllers/spree/admin/orders_controller_decorator.rb:13:in `block (2 levels) in show'
  responders (2.1.0) lib/action_controller/responder.rb:234:in `call'
  responders (2.1.0) lib/action_controller/responder.rb:234:in `default_render'
  responders (2.1.0) lib/action_controller/responder.rb:186:in `to_format'
  spree_core (3.0.1) lib/spree/responder.rb:24:in `to_format'
  responders (2.1.0) lib/action_controller/responder.rb:163:in `respond'
  responders (2.1.0) lib/action_controller/responder.rb:156:in `call'
  responders (2.1.0) lib/action_controller/respond_with.rb:203:in `respond_with'
  spree_core (3.0.1) lib/spree/core/controller_helpers/respond_with.rb:16:in `respond_with'
  /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/bundler/gems/spree_print_invoice-a4b8acfcaedf/app/controllers/spree/admin/orders_controller_decorator.rb:9:in `show'
  actionpack (4.2.2) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.2.2) lib/abstract_controller/base.rb:198:in `process_action'
  actionpack (4.2.2) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.2.2) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.2.2) lib/active_support/callbacks.rb:117:in `call'
  activesupport (4.2.2) lib/active_support/callbacks.rb:117:in `call'
  activesupport (4.2.2) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
  activesupport (4.2.2) lib/active_support/callbacks.rb:505:in `call'
  activesupport (4.2.2) lib/active_support/callbacks.rb:505:in `call'
  activesupport (4.2.2) lib/active_support/callbacks.rb:92:in `_run_callbacks'
  activesupport (4.2.2) lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
  activesupport (4.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.2) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.2.2) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.2.2) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (4.2.2) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.2) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (4.2.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.2.2) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.2.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.2.2) lib/abstract_controller/base.rb:137:in `process'
  actionview (4.2.2) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.2.2) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.2.2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.2.2) lib/action_controller/metal.rb:237:in `block in action'
  actionpack (4.2.2) lib/action_dispatch/routing/route_set.rb:74:in `call'
  actionpack (4.2.2) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
  actionpack (4.2.2) lib/action_dispatch/routing/route_set.rb:43:in `serve'
  actionpack (4.2.2) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.2) lib/action_dispatch/journey/router.rb:30:in `each'
  actionpack (4.2.2) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.2) lib/action_dispatch/routing/route_set.rb:819:in `call'
  railties (4.2.2) lib/rails/engine.rb:518:in `call'
  railties (4.2.2) lib/rails/railtie.rb:194:in `public_send'
  railties (4.2.2) lib/rails/railtie.rb:194:in `method_missing'
  actionpack (4.2.2) lib/action_dispatch/routing/mapper.rb:51:in `serve'
  actionpack (4.2.2) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.2) lib/action_dispatch/journey/router.rb:30:in `each'
  actionpack (4.2.2) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.2) lib/action_dispatch/routing/route_set.rb:819: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.6.4) lib/rack/etag.rb:24:in `call'
  rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
  rack (1.6.4) lib/rack/head.rb:13:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/flash.rb:260:in `call'
  rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.2.2) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call'
  activerecord (4.2.2) lib/active_record/migration.rb:378:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.2) lib/active_support/callbacks.rb:88:in `call'
  activesupport (4.2.2) lib/active_support/callbacks.rb:88:in `_run_callbacks'
  activesupport (4.2.2) lib/active_support/callbacks.rb:776:in `_run_call_callbacks'
  activesupport (4.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.2) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.2) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.2) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.2) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.2) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.2) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.2) lib/action_dispatch/middleware/static.rb:113:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.2) lib/rails/engine.rb:518:in `call'
  railties (4.2.2) lib/rails/application.rb:164:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
  /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
  /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
  /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'


  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.2/lib/action_dispatch/middleware/templates/rescues/_source.erb (12.3ms)
  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (6.6ms)
  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (3.3ms)
  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.2/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (268.8ms)
  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (0.7ms)
  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (1.1ms)
  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.6ms)
  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.6ms)
  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/console.js.erb within layouts/javascript (256.3ms)
  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/main.js.erb within layouts/javascript (0.6ms)
  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.7ms)
  Rendered /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/index.html.erb (534.7ms)

我该如何解决这个问题并修复这个错误?

我有同样的错误并通过添加修复它:

/config/initializers/print_invoice.rb 使用以下配置: Spree::PrintInvoice::Config.set(logo_path: 'images/your_image.png')

将 your_image.png 保存在 app/assets/images 文件夹中

重新启动您的服务器,它应该可以工作了。