So I see some code in a Rails 4.2 app like this the below.
1) What type of object is @template in kite_presenter.rb? Is it an instance of ActionView and that is how it has access to helpers such as image_tag? 2) If the answer to 1 is that is an instance of Actionview, in application_helper.rb, how does self know to refer to an ActionView object?
kite_presenter.rb
class KitePresenter < SimpleDelegator
def initialize(kite, template)
super(kite)
@template = template
end
def tail_display
h.image_tag("tail.png", class: 'gray')
end
end
application_helper.rb
module ApplicationHelper
def present(object, klass = nil)
klass ||= "#{object.class}Presenter".constantize
presenter = klass.new(object, self)
yield presenter if block_given?
presenter
end
end
some_html.erb
<% present(kite) do |kite_presenter| %>
<%= kite_presenter.tail_display %>
<% end %>