You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Presenter is a class that is aware of both your Model and your View. Your ApplicationHelper should create these instances by calling MyPresenter.new(object, self), meaning that template within the Presenter is a reference to the view rendering context, giving you access to all of the helper methods that would be available in a view template.
you initialize it like this from a presenter helper method, where the helper method passes self into the presenter. In a View Helper, self is a view context. You could call it view_context, template, or helper. It is not a Controller.
Blacklight::DocumentPresenter uses the wrong names to do the right thing
In [app/helpers/concerns/blacklight_helper_behavior.rb]
### Returns a document presenter for the given documentdefpresenter(document)presenter_class.new(document,self)end
This matches with the canonical implementation of this pattern. The second argument is a view context, not a controller. This doesn't match with what the DocumentPresenter says it expects: [app/presenters/blacklight/document_presenter.rb]
# @param [SolrDocument] document# @param [ActionController::Base] controller scope for linking and generating urls# @param [Blacklight::Configuration] configurationdefinitialize(document,controller,configuration=controller.blacklight_config)@document=document@configuration=configuration@controller=controllerend
The DocumentPresenter is mis-naming that variable and the documentation on that class is incorrect. It claims to want an ActionController::Base as its second argument and calls it "@controller" but really it's getting a view_context, which is what it should be getting, and it should call it either view_context, template, or helper.
The Pattern
A Presenter is a class that is aware of both your Model and your View. Your ApplicationHelper should create these instances by calling
MyPresenter.new(object, self)
, meaning thattemplate
within the Presenter is a reference to the view rendering context, giving you access to all of the helper methods that would be available in a view template.you initialize it like this from a
presenter
helper method, where the helper method passesself
into the presenter. In a View Helper,self
is a view context. You could call itview_context
,template
, orhelper
. It is not a Controller.Blacklight::DocumentPresenter uses the wrong names to do the right thing
In [app/helpers/concerns/blacklight_helper_behavior.rb]
This matches with the canonical implementation of this pattern. The second argument is a view context, not a controller. This doesn't match with what the DocumentPresenter says it expects: [app/presenters/blacklight/document_presenter.rb]
The DocumentPresenter is mis-naming that variable and the documentation on that class is incorrect. It claims to want an
ActionController::Base
as its second argument and calls it "@controller
" but really it's getting a view_context, which is what it should be getting, and it should call it eitherview_context
,template
, orhelper
.References
http://nithinbekal.com/posts/rails-presenters/
http://railscasts.com/episodes/287-presenters-from-scratch?autoplay=true
The text was updated successfully, but these errors were encountered: