I use the excellent Inherited Resources gem quite a bit in my Rails apps, but whenever I want to use a presenter I fall back to writing controllers by hand.
Is there a good, clean solution for combining Inherited Resources with something like Draper or delegate_presenter?
Author of
delegate_presenter
here.delegate_presenter
should work just fine withinherited_resources
. Now I haven't actually used inherited_resources on a project, so a lot of this is just from the readme.What I always to do create the presenter object in the view anyway:
todo_present = Present(@todo)
, for example.If you are having templates from a common source (like
LegalTodo
is a subclass ofTodo
, for some bog-unknown reason), and you share templates, you could do this in your template:presenter = Present(resource)
resource
- at least according to the inherited_resources readme - is the helper for the current resource your looking at (so,@todo
, or@legal_todo
)Present()
will look at the class of the object and instantiate the appropriate presenter object.TodoPresenter
ifresource
returns aTodo
object,LegalTodoPresenter
ifresource
returns aLegalTodo
object.Then, assuming those presenters are polymorphic, the presenters will let you abstract the differences away ("The name of a
LegalTodo
be the description + deposition number, but the name of theTodo
item should just be description") - even if you share views!