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_presenterhere.delegate_presentershould 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
LegalTodois 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.TodoPresenterifresourcereturns aTodoobject,LegalTodoPresenterifresourcereturns aLegalTodoobject.Then, assuming those presenters are polymorphic, the presenters will let you abstract the differences away ("The name of a
LegalTodobe the description + deposition number, but the name of theTodoitem should just be description") - even if you share views!