Decorate Devise current_user with Draper24 Jan 2017
Draper is awesome.
I normally use the handy
decorates_assigned method to decorate model
objects in controllers.
Devise makes the
currently signed in user available through a
current_admin, etc.) method. To decorate this with your Draper
UserDecorator, just add the following method to
protected def current_user super&.decorate end
This just calls
decorate on the model object returned by the Devise
&. is Ruby 2.3’s safe
method and ensures that the call to
decorate doesn’t raise an
exception if no user is signed in (
current_user is nil). For older
Ruby versions, you can use Rails’
h.t. Ariejan de Vroom for the original idea.