In the Rails Engine application you need to connect gem draper . After completing all the instructions on the docks, namely:

After installing the gem and executing the rails generate decorator command, I create the decorator:

 class OrderDecorator < Draper::Decorator delegate_all delegate :hide_part_number, :expiration_date, to: :credit_card, prefix: true decorates_association :credit_card decorates_association :shipping_address decorates_association :billing_address decorates_association :order_items end 

When starting the application, it crashes Error screenshot

My engine_name.gemspec.rb

 s.add_dependency "rails", "~> 5.0.0", ">= 5.0.0.1" s.add_dependency 'aasm', '~> 4.10', '>= 4.10.1' s.add_dependency 'wicked', '~> 1.3' s.add_dependency 'haml', '~> 4.0', '>= 4.0.7' s.add_dependency 'bootstrap-sass', '~> 3.3', '>= 3.3.6' s.add_dependency 'draper', '~> 2.1' s.add_dependency 'activesupport-decorators', '~> 1.0' s.add_development_dependency 'pg' 

On one of the sites I found advice on how to overcome this problem, but unfortunately did not help:

There I advise you to add to engine.rb

 config.to_prepare do Dir.glob(Rails.root + 'app/decorators/**/*_decorator*.rb').each do |c| require_dependency(c) end end 

But that did not change anything.

  • Take a debugger, and ... find out if there is a decorator class at all. Is the gem draper . I have advised you to master the debugger at some point? .. - D-side
  • There is a suspicion that you have OrderDecorator , and the ShoppingCart::OrderDecorator model does a mismatch, but you can say for sure only by checking this theory. - D-side
  • Apparently, your Order model is not loaded, if it should be in the ShoppingCart space at all, or more precisely the wrong model is loaded. As far as I understand, just OrderDecorator is applied spontaneously only to the top-level model. - Mal Skrylev

1 answer 1

In the controller, when decorating a collection or an object (for example, @orders ), specify the decorator class explicitly using the with option

 class ShoppingCard::OrdersController < ActionController::Base ... decorates_assigned :orders, with: OrderDecorator ...