Ro r trilogy-part-1

478 views
394 views

Published on

The Ruby on Rails Trilogy - a new Dev hope

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

  • Be the first to like this

No Downloads
Views
Total views
478
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ro r trilogy-part-1

  1. 1. AMIR BARYLKO THE ROR TRILOGY A NEW DEV HOPEAmir Barylko RoR Trilogy Part I: A New Dev Hope
  2. 2. WHO AM I? • Software quality expert • Architect • Developer • Mentor • Great cook • The one who’s entertaining you for the next hour!Amir Barylko RoR Trilogy Part I: A New Dev Hope
  3. 3. RESOURCES • Email & Twitter: amir@barylko.com, @abarylko • Slides: http://www.orthocoders.com/presentations • Company Site: http://www.maventhought.com • Try Ruby online: http://tryruby.org/ • Learn RoR online: http://railsforzombies.org/Amir Barylko RoR Trilogy Part I: A New Dev Hope
  4. 4. RUBY INTRO Dynamic languages Features Support Classes MixinsAmir Barylko RoR Trilogy Part I: A New Dev Hope
  5. 5. DYNAMIC LANGUAGES • High level • Dynamically typed • Runtime over compile time • Closures • Reflection • Platform independentAmir Barylko RoR Trilogy Part I: A New Dev Hope
  6. 6. WELCOME TO RUBY • Created in mid-90s by • Automatic memory “Matz” Matsumoto in Japan management • Smalltalk, Perl influences • Several implementations: MRI, YARB, JRuby • Dynamic typing • Totally free!! • Object OrientedAmir Barylko RoR Trilogy Part I: A New Dev Hope
  7. 7. RUBY FEATURES • Everything is an expression • Metaprogramming • Closures • Garbage collection • Exceptions • Operator overloading, flexible syntaxAmir Barylko RoR Trilogy Part I: A New Dev Hope
  8. 8. RUBY SUPPORT • Hundreds of books • User conferences all over the world • Active community (you can create a conference in your own city and top Ruby coders will go there to teach others, invite them and see) • Lots of great web sites: basecamp, twitter, 43 things, hulu, scribd, slideshare, Justin.tvAmir Barylko RoR Trilogy Part I: A New Dev Hope
  9. 9. CLASSES & OBJECTS • Initializer and instance variables class Movie def initialize(name) @name = name end def play puts %Q{Playing “#{@name}”. Enjoy!} end end m = Movie.new(“Pulp fiction”) m.play => Playing “Pulp fiction”. Enjoy!Amir Barylko RoR Trilogy Part I: A New Dev Hope
  10. 10. CLASSES & OBJECTS II • Attributes class Movie # attr reader and writer attr_accesor :name def initialize(name) @name = name end end m = Movie.new(Brazil) m.name = “Pulp fiction”Amir Barylko RoR Trilogy Part I: A New Dev Hope
  11. 11. MIXINS • One of the greatest Ruby features! • You can define functions in Modules, and get them added to your classes. • Great code reuse, • Multiple inheritance alternative. • Code organizationAmir Barylko RoR Trilogy Part I: A New Dev Hope
  12. 12. ENUMERABLE MIXIN • Quote from the standard library documentation: ...The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method each, which yields successive members of the collection...Amir Barylko RoR Trilogy Part I: A New Dev Hope
  13. 13. ENUMERABLE II • It provides useful methods such as: • map • to_a • take_while • count • injectAmir Barylko RoR Trilogy Part I: A New Dev Hope
  14. 14. MIXIN EXAMPLE class MovieLibrary include Enumerable def each(&block) contents.each(&block) end endAmir Barylko RoR Trilogy Part I: A New Dev Hope
  15. 15. ROR What is it? Convention over configuration Model View Controller Code generation Dependency Management HTML 5 & UJSAmir Barylko RoR Trilogy Part I: A New Dev Hope
  16. 16. WHAT IS ROR? • Web application development framework • Created by David Heinemeier Hansson • With Rails, you would be done by now! • Open Source & Multi platform • Very easy to learn • Comes with everything out of the box!Amir Barylko RoR Trilogy Part I: A New Dev Hope
  17. 17. CONVENTION OVER CONFIGURATION • All applications share the same structure • The application is generated by the rails command • All the config files are ruby codeAmir Barylko RoR Trilogy Part I: A New Dev Hope
  18. 18. MODEL VIEW CONTROLLER • Model: represents the data • Controllers: Manipulate the data and prepare it to be shown • View: Shows the data with a particular view engineAmir Barylko RoR Trilogy Part I: A New Dev Hope
  19. 19. CODE GENERATION • Using rails command: • Bootstrap: Generates basic structure • Models: Generated models and tests • Controllers: Generates controllers, views and tests • Scaffolds: Generates models, controllers, views, routes, etc...Amir Barylko RoR Trilogy Part I: A New Dev Hope
  20. 20. DEPENDENCY MANAGEMENT • Gems are Ruby libraries • Dependencies are managed with tool gem • To install a gem just run: gem install xxxxxx • Bundler is a gem to manage dependencies • Just create a Gemfile and bundler will install all of themAmir Barylko RoR Trilogy Part I: A New Dev Hope
  21. 21. HTML 5 & UNOBTRUSIVE JS • Supports HTML 5 standards • data-remote, data-method, data-config, etc... • Supports many JS frameworks • JS code associated to models to handle events, animations, etc • Coffeescript!Amir Barylko RoR Trilogy Part I: A New Dev Hope
  22. 22. ROR GOODNESS Common Structure Automation Migrations ActiveRecord Testing ScaffoldingAmir Barylko RoR Trilogy Part I: A New Dev Hope
  23. 23. COMMON STRUCTURE • app • assets: Stylesheets, javascript, images • controllers: Prepare the data for the views • helpers: Helper methods to render views • models: Represent our domain • views: Templates to be rendered • each controller has a folder with one template per method • layouts:Base templates to surround the viewsAmir Barylko RoR Trilogy Part I: A New Dev Hope
  24. 24. AUTOMATION • Rake is a build tool (similar to ant, msbuild, maven) • Has tasks that can be configured • Out of the box has common tasks for database, testing, etc.. • List all the tasks: rake -T • Very useful to automate tasks and to use in CI serversAmir Barylko RoR Trilogy Part I: A New Dev Hope
  25. 25. MIGRATIONS • Track the database changes using code • No need to use SQL • Upgrades are easy • Versioning is kept in the database • Generated automatically when creating modelsAmir Barylko RoR Trilogy Part I: A New Dev Hope
  26. 26. ACTIVE RECORD • Relations (ActiveModel) • Supports multiple databases • Each table is a class • All attributes are created dynamically • Associations are declared by convention • Each class has CRUD and query operations by defaultAmir Barylko RoR Trilogy Part I: A New Dev Hope
  27. 27. TESTING OUT OF THE BOX • Many testing frameworks available • No additional effort to generate them • Running them is part of the Rakefile (automation) • Keep high quality all the wayAmir Barylko RoR Trilogy Part I: A New Dev Hope
  28. 28. SCAFFOLDING • Generated automatically for CRUD operations • Controllers • Views • Tests • The template used can be replaced of modifiedAmir Barylko RoR Trilogy Part I: A New Dev Hope
  29. 29. MOVIE LIBRARY DemoAmir Barylko RoR Trilogy Part I: A New Dev Hope
  30. 30. TOPICS • Rails application structure • Database Migrations • Using scaffolds • Model - View - Controllers • Routing • AjaxAmir Barylko RoR Trilogy Part I: A New Dev Hope
  31. 31. MORE GOODNESS! Helpers Partials Sass RoutingAmir Barylko RoR Trilogy Part I: A New Dev Hope
  32. 32. HELPERS • Methods to assist in the view generation • Reusable • Associated to each controller • TestableAmir Barylko RoR Trilogy Part I: A New Dev Hope
  33. 33. PARTIALS • Templates that can be shared • Start with underscore “_” • Can be rendered from views or controllersAmir Barylko RoR Trilogy Part I: A New Dev Hope
  34. 34. SASS • Quote from sass-lang.com: Sass is an extension of CSS3, adding nested rules, variables, mixins,selector inheritance, and more. It’s translated to well-formatted, standard CSS using the command line tool or a web-framework plugin.Amir Barylko RoR Trilogy Part I: A New Dev Hope
  35. 35. ROUTING • Easy to configure using routes.rb • Supports REST out of the box • Easy to restrict actions • Easy to alias routes • Allows optional parameters in the routesAmir Barylko RoR Trilogy Part I: A New Dev Hope
  36. 36. QUESTIONS?
  37. 37. RESOURCES • Email & Twitter: amir@barylko.com, @abarylko • Slides: http://www.orthocoders.com/presentations • Company Site: http://www.maventhought.com • Try Ruby online: http://tryruby.org/ • Learn RoR online: http://railsforzombies.org/Amir Barylko RoR Trilogy Part I: A New Dev Hope
  38. 38. RESOURCES IIAmir Barylko RoR Trilogy Part I: A New Dev Hope
  39. 39. CLOJURE TRAINING • When: Nov 6, 7 & 8 • More info: http://www.maventhought.com • Goal: LearnClojure and functional programming with real hands on examplesAmir Barylko RoR Trilogy Part I: A New Dev Hope

×