drapergem / draper

Decorators/View-Models for Rails Applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rails - STI bug for ActiveRecord_Relation, works fine for a single record

james-em opened this issue · comments

Simple explanation of the bug

MyModelBase.all.decorate
=> Could not infer a decorator for MyModelBase. (Draper::UninferrableDecoratorError)

MyModelBase.all.first.decorate
=> #<MyModelSpecificDecorator:0x000000012116d470

Workaround
PS: Can cause some performance drawbacks in some cases

MyModelBase.all.map(&:decorate)

Expected behavior

MyModelBase.all.decorate shouldn't raise an error.

The question is: What result do you expect? What class do you want it to be / what methods to have?

  1. You may define basic MyModelBasesDecorator < Draper::CollectionDecorator. It may be empty, that will do.

  2. If you don't want to for some reason, you can use a basic collection decorator: Draper::CollectionDecorator.decorate MyModelBase.all explicitly. Every record will be decorated with a decorator matching its class as in case 1.