Using a Decorator, (rails) Could not infer a decorator for ActiveRecord::Base

牧云@^-^@ 提交于 2019-12-10 15:55:14

问题


I'm having trouble using a decorator. I've never used one before and I've been trying to use one with regards to something that I've been doing for breaking up some emails.

However because I've never used one before, I've been having trouble even doing very simple things with my decorator and I'm thinking there is some form of setup issue with it. I do know that everything outside of my little feature (aka the gemfile and such) are all up to date and proper.

The error I am getting is simply,

Could not infer a decorator for ActiveRecord::Base.

Now I have a controller that is almost empty, but inside it, I have the active record portion saved like so.

class Admin::ReceivedEmailsController < Admin::ApplicationController

With my view being titled,

_receive_email.html.haml

All I am doing in my view as of right now is so:

  %td= received_email.decorate

My decorator

class Admin::ReceivedEmailsDecorator < Admin::ApplicationDecorator

def received_email
 if can? :update, @customer
   received_email.content
 else
   "You need to have the correct admin access to view the email"
 end
end

I feel like this would have to be such an elementary thing for me to be missing, but I'm not sure what it is. Would anybody have any idea what I'm missing?


回答1:


After much further research, reverse engineering further decorators and reading more documentation. I learned that a model or a helper is needed for a decorator to be properly used. Which due to my partial I did not have one specific model or helper to use.



来源:https://stackoverflow.com/questions/33877328/using-a-decorator-rails-could-not-infer-a-decorator-for-activerecordbase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!