RailsCasts Pro episodes are now free!

Learn more or hide this

Scott Olmsted's Profile

GitHub User: sandiegoscott

Comments by Scott Olmsted

Avatar

What if I want to use HAML in the presenter? I added lines to BasePresenter like so:

ruby
class BasePresenter
  include Haml::Helpers  # access HAML

  def initialize(object, template)
    @object = object
    @template = template
    init_haml_helpers  # init the helpers
  end

  def self.presents(name)
    define_method(name) do
      @object
    end
  end

  def h
    @template
  end

  #---------------------------------------------

  def show_field( label, contents, options=nil )
    haml_tag 'tr' do
      haml_tag 'td.label', label, options
      haml_tag 'td.field', contents ||= ''
    end
  end

end

and used it like this in show.haml:

ruby
- presenter.show_field('Efficacy', presenter.efficacy)

and I can show that show_field is being called, but no HTML is produced. Maybe it is in the wrong context.

Avatar

Shouldn't this line:

ruby
klass ||= "{object.class}Presenter".constantize

be

ruby
klass ||= "#{object.class}Presenter".constantize

?