HomePresenters::ShowPresenter and use model methods (and scopes) directly. I don’t think Presenter role is to fetch data anyway. Actually Cells do all the work we need here. And if you use decorators (Draper), everything works just fine.
]]>1 2 3 4 5 | Autotest.add_hook :initialize do |at| at.add_mapping(%r%^app/presenters/(.*)\.rb$%) { |_, m| ["spec/presenters/#{m[1]}_spec.rb"] } end |
How would you go about adding its specs to autospec? It doesn’t seem to include them automatically.
]]>This technique is really invaluable as your app grows and you end up with small encapsulated bits of logic that are too big/messy for partials/helpers but are also kind of inappropriate for your models and controllers.
I’m really hoping something like this, or a conversion of Merb Parts, finds its way into Rails 3.
]]>The example in this article may not be sufficiently complex to justify for inheritance between Cells, but believe me that this can tremendously simplify an app (compared with complex shared view partials).
]]>Representers, Proxies, Factories, whatever, sometimes what you’ll get is just another level of abstraction, not really useful at all on a second thought. Please, don’t bring that hell to ruby.
Back to subject: Long time ago we had components, but then world was filled with rumours about them being “slow”, and suddenly they fell out of usage and rails core. I yet to see them reintroduced back, in core, lightweight and isolated, but meanwhile both representers and cells functionality could be easily achieved using helpers alone, and I do it all the time.
differences are:
1) you have the same namespace for @vars (but locals are just as good) and helper names. It’s a bad thing because of possible nameclashes, but it’s a good thing for ctags and grep users. <%= video_link @video, :style => :brief %> is DRY enough
2) you’ll get ActionView::TemplateError with 500 status instead of 404 ActiveRecord::NotFound if you trigger some faulty Model.find in helper and not in controller, but it’s not a big deal and it could be fixed by several plugins.
3) there’s no default place for such helpers, so what i have to do is just to group “presenter helpers” and “cell and decoration helpers” in different helper modules or in different sections of same “resource specific” helper module.
]]>From a quick look at Cell::View#render it seems that it could be updated to match the Rails version, but can’t be sure about that.