Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Gavin Morrice's Profile

GitHub User: Bodacious

Site: www.gavinmorrice.com

Comments by Gavin Morrice

Avatar

Understood - would be good to see more on Metal though :)

Particularly, the common pitfalls when trying to include behaviour that may be strewn across two or three ActionController modules

Avatar

I just discovered RABL - me gusta!

Avatar

Great idea and well presented as usual Ryan...

Title was a little misleading though :/

Avatar

I've having a problem with this too - did you ever solve this?

Avatar

You're totally right / I completely overlooked the two arguments making my solution wrong.

Generally, I don't like the "class goes in, instance comes out" approach but I think it's fine in this case

Avatar

Suggested refactor:

ruby
module ApplicationHelper
  def present(object, presenter = "#{object.class}Presenter".constantize.new )
    yield presenter if block_given?
    presenter
  end
end

It's better to pass an instance as a parameter than a class

rhtml
<% present @user, UserPresenter.new do %>

  <!--- stuff --> 

<% end %>

<!-- or -->

<% present @user do %>

  <!--- stuff --> 

<% end %>
Avatar

I'd +1 that

My favourite ruby book of all time is Metaprogramming Ruby

The thing I loved most about this book is that BDD is part of every example. I always feel that by showing just the code, you're only showing half of the solution to a problem?