My questions refers to the following development stack:
我的问题涉及以下开发堆栈:
- Rails 3.2.1
- Rails 3.2.1之上
- Draper 0.14
- 德雷伯0.14
- Ancestry 1.2.5
- 祖先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
.
我想做的是,将导航发送到我的布局。我在应用程序控制器中定义了一个before过滤器。
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?
正如您在上面的代码清单中看到的,我正在使用draper。我的PublicationDecorator在ApplicationController中不可用。那么我该如何装饰我所有的出版物呢?
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
?
我正在使用祖先宝石来实现等级。进一步的问题是,如果我使用祖先,所有的物品会被装饰吗?
1 个解决方案
#1
3
Make your PublicationDecorator
available in your ApplicationController
.
让您的PublicationDecorator在您的应用程序控制器中可用。
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
#1
3
Make your PublicationDecorator
available in your ApplicationController
.
让您的PublicationDecorator在您的应用程序控制器中可用。
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