How should I use Draper in my ApplicationController?
decorator, hierarchy, ruby-on-rails
Solution
Make your `PublicationDecorator` available in your `ApplicationController`.
require 'publication_decorator.rb' # <--
class ApplicationController < ActionController::Base
[..]
before_filter :current_navigation
[..]
def current_navigation
@n = PublicationDecorator.find(1)
end
end
To get children or even parents decorated add the association to your decorator:
class PublicationDecorator < Draper::Base
decorates :publication
decorates_association :children
[..]
end
Problem
My questions refers to the following development stack: - Rails 3.2.1 - Draper 0.14 - Ancestry 1.2.5 What I want to do is, deliver the navigation to my layout. So I've defined a before filter in my `ApplicationController`. ``` class ApplicationController < ActionController::Base [..] before_filter :current_navigation [..] def current_navigation @n = PublicationDecorator.find(1) end end ``` As you see in the code listing above, I'm using the `draper`. My `PublicationDecorator` isn't available in the `ApplicationController`. So how do I get all my `Publications` decorated? ``` uninitialized constant ApplicationController::PublicationDecorator ``` I'm using the `ancestry` gem to realize a hierarchy. A further question is, will be all objects decorated, if I'm using `ancestry`?