4

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?

Robin
  • 8,162
  • 7
  • 56
  • 101
  • similar to http://stackoverflow.com/questions/10884740/nested-attributes-with-draper-and-rails-3 – Robin Jun 07 '12 at 20:23

1 Answers1

3

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
Robin
  • 8,162
  • 7
  • 56
  • 101
Sandip Mondal
  • 921
  • 7
  • 12
  • Thank you for your answer! My question is more about, whether I've understood to use the given technology in this situation. Please heed my 'between' and 'further' question. – Robin Jun 04 '12 at 19:00
  • Added some information to your answer that it complettly answer my question. – Robin Jun 07 '12 at 20:25