Marcel Molina Jr. Presentation

2,003 views
1,921 views

Published on

Published in: Business, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,003
On SlideShare
0
From Embeds
0
Number of Embeds
41
Actions
Shares
0
Downloads
52
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Marcel Molina Jr. Presentation

  1. 1. Sharing RJS: Reuse at the app level Marcel Molina Jr. 37signals 1
  2. 2. A little bit about me 2
  3. 3. Member of Rails Core Thomas Fuchs Jeremy Kemper Michael Koziarski Jamis Buck Tobias Lütke Sam Stephenson Rick Olson Nicholas Seckar Some of the people you trust your business to... 3
  4. 4. Work for 37signals 4
  5. 5. Hottest Hacker On Earth David Has And Belongs To Many Hanssons 5
  6. 6. Sharing RJS 6
  7. 7. Typical RJS app/controllers/articles_controller.rb 7
  8. 8. Duplication Oops app/controllers/articles_controller.rb 8
  9. 9. Let’s fix this 9
  10. 10. Extract to private method of controller app/controllers/articles_controller.rb 10
  11. 11. Wrong scope! Oops app/controllers/articles_controller.rb 11
  12. 12. Extract to helper, passing page app/helpers/articles_helper.rb 12
  13. 13. This works app/controllers/articles_controller.rb 13
  14. 14. But it’s Pythonic :-( Oops app/controllers/articles_controller.rb 14
  15. 15. Monkey patch JavaScriptGenerator!!! 15
  16. 16. Define custom helpers directly on page!!! app/helpers/articles_helper.rb 16
  17. 17. That’s more like it!!! app/controllers/articles_controller.rb 17
  18. 18. Page “namespace” is already reserved Oops app/controllers/articles_controller.rb 18
  19. 19. JavaScriptProxy or custom helper?! app/controllers/articles_controller.rb 19
  20. 20. Maintenance headache public/javascripts/application.js app/controllers/articles_controller.rb app/helpers/articles_helper.rb 20
  21. 21. Method missing abuse Oops app/controllers/articles_controller.rb 21
  22. 22. What now? 22
  23. 23. Let’s look back to the origins of RJS 23
  24. 24. Initial API for Ajax in Rails 24
  25. 25. Indicates which element to update 25
  26. 26. Faced with a tricky problem 26
  27. 27. :update won’t cut it 27
  28. 28. Wouldn’t it be nice if you could...? 28
  29. 29. Thanks Ruby :-) 29
  30. 30. Initial API 30
  31. 31. Ugly. Not quite right. Oops 31
  32. 32. Wrap it up in a new template type actionpack/lib/action_view/base.rb 32
  33. 33. Just update_page under the sheets actionpack/lib/action_view/base.rb 33
  34. 34. update_page just spits out JavaScript 34
  35. 35. << just adds raw JavaScript to the stream is the same as 35
  36. 36. So... 36
  37. 37. Wrap update_page in a helper app/helpers/articles_helper.rb 37
  38. 38. Reuse it with << app/controllers/articles_controller.rb 38
  39. 39. Bonus 39
  40. 40. Reuse it client side 40
  41. 41. Having said all that... 41
  42. 42. No use obviates reuse app/helpers/application_helper.rb public/stylesheets/screen.css app/views/articles/edit.rhtml 42
  43. 43. Questions, comments & etc 43
  44. 44. Questions, comments & etc Thanks 44

×