How can I use an application decorator for site-wide view logic?

414 views Asked by At

After watching the recent Railscasts episode on Draper I thought I'd have a go at refactoring some of my stuff to make use of the Decorator pattern. And then instantly managed to confuse myself.

I have view logic in my application layout file that provides login or logout links depending on whether (wait for it) you're logged in or not:

<% if signed_in? %>
  <li><%= link_to "Sign out", signout_path, :method => :delete %></li>
<% else %>
  <li><%= link_to "Sign in", signin_path %></li>
<% end %>

Seems like a perfect candidate for moving that logic into a decorator. But this is an app wide bit of view logic, so what am I decorating? I guess I want to create an application decorator, but I'm unclear of how to instantiate the app decorator object and how to reference it.

The Railscasts episode does show how to create an app decorator, but it's referenced from within a specific controller (i.e. not the app controller). How do I structure things so I can access the decorated view logic from every page on the site?

0

There are 0 answers