0

In user's home page I want to show the user's phrases.

class StaticPagesController < ApplicationController
  def home
    if user_signed_in?
      @phrases = current_user.phrases.decorate
    end
  end
end

But this fails by Could not infer a decorator. I understand the error happens because only in proper controller I can use the decorate method. I've read this post, but I may misunderstand it.

So if I want to use decorate method in situation like this, what is a good way to solve it?

Community
  • 1
  • 1
ironsand
  • 14,329
  • 17
  • 83
  • 176
  • 1
    I suppose what `current_user.phrases` return an array, do you have decorator for array? maybe you should use decorator on the instance of `phrase` in the related views? – Roman Kiselenko Dec 07 '15 at 10:09
  • I see, thanks! But there is still `Could not infer a decorator for ActiveRecord::Base.` error, when I call `phrase.decorate` in view. – ironsand Dec 07 '15 at 10:45
  • Ops, sorry! I forgot to restart rails server. After restart it works fine! – ironsand Dec 07 '15 at 10:47

0 Answers0