Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
PRESENTERS 
with a guest appearance from decorators
HI 
• tomridge2@gmail.com 
• @tjridge 
• github.com/ridget
LETS BUILD AN APP
VIEW RELATED LOGIC 
• welp
LETS PUT IT IN A HELPER!
HELPERS AREN’T AWESOME 
• at least for this task 
• they share a global namespace 
• aren’t a very oo way of solving the p...
I KNOW MODELS! 
• also nope 
• All these if conditions relate to the display of data 
• Don’t overload your model with tha...
ENTER PRESENTERS 
• Presenters are a simple class with knowledge of 
the model and the view. 
• Not a stretch to call them...
PURPOSE 
• Presenters help to achieve adherence to SRP 
• A Presenter’s purpose is a decorator who has the 
job of massagi...
DECORATOR? 
• Taking one object and adding, replacing or 
extending its behaviour, whilst allowing access to 
the underlyi...
PRESENTERS VS DECORATORS 
• A decorator isn’t always a presenter, but a 
presenter is always likely to be a decorator.
END RESULT 
• This is more in line with a decorator approach 
• We just delegate to the underlying object
MULTIPLE OBJECTS? 
• ensure you delegate methods to the underlying 
objects
MULTIPLE RECORDS? 
• Just create a wrap method to instantiate your 
presenter/decorator across multiple records.
OTHER OPTIONS? 
• Draper 
• Great for when things start getting more 
complex
OTHER VALUE POINTS 
• Easy-ish to test 
• less conditionals in your views 
• happier designers/front end developers
CONS 
• More objects == harder to learn the codebase 
• Don’t introduce them until you need to.
GREAT RESOURCES 
• Railscasts - draper and presenters from scratch 
(pro) 
• http://new-bamboo.co.uk/blog/2013/04/17/rails...
QUESTIONS?
Rails Presenters
Upcoming SlideShare
Loading in …5
×

Rails Presenters

259 views

Published on

A quick run down on the presenter pattern in rails, code for the talk is here https://github.com/ridget/presenters_app

Published in: Software
  • Be the first to comment

  • Be the first to like this

Rails Presenters

  1. 1. PRESENTERS with a guest appearance from decorators
  2. 2. HI • tomridge2@gmail.com • @tjridge • github.com/ridget
  3. 3. LETS BUILD AN APP
  4. 4. VIEW RELATED LOGIC • welp
  5. 5. LETS PUT IT IN A HELPER!
  6. 6. HELPERS AREN’T AWESOME • at least for this task • they share a global namespace • aren’t a very oo way of solving the problem • great for shared logic that doesn't relate to the object. Use sparingly
  7. 7. I KNOW MODELS! • also nope • All these if conditions relate to the display of data • Don’t overload your model with that level of responsibility
  8. 8. ENTER PRESENTERS • Presenters are a simple class with knowledge of the model and the view. • Not a stretch to call them a ViewModel
  9. 9. PURPOSE • Presenters help to achieve adherence to SRP • A Presenter’s purpose is a decorator who has the job of massaging the decorated object into a ui/ view friendly manner.
  10. 10. DECORATOR? • Taking one object and adding, replacing or extending its behaviour, whilst allowing access to the underlying objects methods.
  11. 11. PRESENTERS VS DECORATORS • A decorator isn’t always a presenter, but a presenter is always likely to be a decorator.
  12. 12. END RESULT • This is more in line with a decorator approach • We just delegate to the underlying object
  13. 13. MULTIPLE OBJECTS? • ensure you delegate methods to the underlying objects
  14. 14. MULTIPLE RECORDS? • Just create a wrap method to instantiate your presenter/decorator across multiple records.
  15. 15. OTHER OPTIONS? • Draper • Great for when things start getting more complex
  16. 16. OTHER VALUE POINTS • Easy-ish to test • less conditionals in your views • happier designers/front end developers
  17. 17. CONS • More objects == harder to learn the codebase • Don’t introduce them until you need to.
  18. 18. GREAT RESOURCES • Railscasts - draper and presenters from scratch (pro) • http://new-bamboo.co.uk/blog/2013/04/17/rails-presenters- skinny-everything • http://robertomurray.co.uk/blog/2014/decorators-presenters- delegators-rails/
  19. 19. QUESTIONS?

×