Additionally, a decorator has access to Rails helper modules via the
class PersonDecorator < Draper::Decorator
delegate_all
def author_headline
if author == helper.current_user
h.content_tag(:h3, 'You')
else
h.content_tag(:h3, author.name)
end
end
end
Now in your template you just call
Access current_user into decorate like below.
h.current_user
helper
proxy method. This is useful when you want to hide complex logic from the templates.class PersonDecorator < Draper::Decorator
delegate_all
def author_headline
if author == helper.current_user
h.content_tag(:h3, 'You')
else
h.content_tag(:h3, author.name)
end
end
end
Now in your template you just call
@person.author_headline
and you are done. No conditions in the template. Your designers will be thankful!Access current_user into decorate like below.
h.current_user
Nice blog........
ReplyDelete