Comments on: Simplifying your Ruby on Rails code: Presenter pattern, cells plugin https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/ In my blog I'll try to describe about interesting technologies, my discovery in IT and some useful things about programming. Sat, 29 Oct 2011 16:15:23 +0000 hourly 1 https://wordpress.org/?v=6.7.1 By: sobstel https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/comment-page-1/#comment-296473 Sat, 29 Oct 2011 16:15:23 +0000 http://kpumuk.info/?p=937#comment-296473 We could actually get rid of 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.

]]>
By: joost https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/comment-page-1/#comment-285383 Thu, 10 Dec 2009 11:22:40 +0000 http://kpumuk.info/?p=937#comment-285383 Replying to myself, here is how to add the presenter specs to autospec. Put the code below in a .autotest file in your project root.

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
]]>
By: joost https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/comment-page-1/#comment-285380 Thu, 10 Dec 2009 09:10:24 +0000 http://kpumuk.info/?p=937#comment-285380 Nice writeup, I like the simplicity of this particular Presenter.

How would you go about adding its specs to autospec? It doesn’t seem to include them automatically.

]]>
By: Rolly https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/comment-page-1/#comment-284710 Thu, 12 Nov 2009 21:33:53 +0000 http://kpumuk.info/?p=937#comment-284710 Thanks for writing this up.

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.

]]>
By: Emmanuel Gomez https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/comment-page-1/#comment-284680 Wed, 11 Nov 2009 01:26:49 +0000 http://kpumuk.info/?p=937#comment-284680 @alexey: one big advantage that Cells (and other ‘heavier’ approaches) have over helpers/partials is inheritance.

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).

]]>
By: Ennuyer.net » Blog Archive » Rails Reading - November 1, 2009 https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/comment-page-1/#comment-284249 Sun, 01 Nov 2009 11:25:31 +0000 http://kpumuk.info/?p=937#comment-284249 […] Simplifying your Ruby on Rails code: Presenter pattern, cells plugin | Dmytro Shteflyuk’s Hom… […]

]]>
By: Alexey Trofimenko https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/comment-page-1/#comment-283364 Sat, 03 Oct 2009 01:35:33 +0000 http://kpumuk.info/?p=937#comment-283364 one thing I especially love in ruby, you don’t have to think about “patterns” at all. You just write ruby code and use one of them almost intuitivelly, without even remembering it got a big chapter in some Big Java/C++ Book and a Captial Letter Starting Name.

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.

]]>
By: Mislav https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/comment-page-1/#comment-283026 Thu, 17 Sep 2009 18:48:03 +0000 http://kpumuk.info/?p=937#comment-283026 It seems to me that “cells” offer no compelling advantage over simply using presenters with Rails partials.

]]>
By: Dmytro Shteflyuk https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/comment-page-1/#comment-282946 Sat, 12 Sep 2009 08:32:47 +0000 http://kpumuk.info/?p=937#comment-282946 You’re welcome :-) Think, author will accept your pull request quickly.

]]>
By: Evgeniy Dolzhenko https://kpumuk.info/ruby-on-rails/simplifying-your-ruby-on-rails-code/comment-page-1/#comment-282944 Sat, 12 Sep 2009 07:09:07 +0000 http://kpumuk.info/?p=937#comment-282944 Doh :) sorry then,
Btw. is there anything that prevents adding such a semantics?

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.

]]>