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.

Ruby on Rails

12,895 views

Published on

Given together with Miguel Vega at the Open Source Health Care Alliance Conference (OSHCA) 2007

Published in: Technology, Design
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Ruby on Rails

  1. 1. Ruby on Rails By Miguel Vega [email_address] http://www.upstrat.com/ and Ezwan Aizat bin Abdullah Faiz [email_address] http://rails.aizatto.com/ http://creativecommons.org/licenses/by/3.0/
  2. 2. Who Am I? <ul><li>Miguel Vega </li></ul><ul><li>1 ½ years doing Ruby and Rails </li></ul><ul><li>PHP before then </li></ul><ul><li>Started a company (upstrat) just to have an excuse to use rails. </li></ul>
  3. 3. Who Am I? <ul><li>Multiple Names </li></ul><ul><ul><li>Ezwan Aizat Bin Abdullah Faiz </li></ul></ul><ul><ul><li>Aizat Faiz </li></ul></ul><ul><ul><li>aizatto </li></ul></ul><ul><ul><li>That scrubby looking guy on the screen </li></ul></ul><ul><li>Student </li></ul><ul><li>Free and Open Source (FOSS) Enthusiast </li></ul><ul><li>Local FOSS Champion </li></ul><ul><ul><li>http://foss.org.my </li></ul></ul><ul><li>Web Developer </li></ul><ul><ul><li>Ruby on Rails </li></ul></ul><ul><ul><li>LAMP </li></ul></ul>
  4. 4. <ul><ul><li>What is </li></ul></ul><ul><ul><li>Ruby on Rails? </li></ul></ul>
  5. 5. <ul><ul><li>Built on </li></ul></ul><ul><ul><li>Ruby Programming Language </li></ul></ul>
  6. 6. <ul><ul><li>Web Application Framework </li></ul></ul>
  7. 7. + =
  8. 8. <ul><ul><li>Wait! </li></ul></ul><ul><ul><li>Unexpected </li></ul></ul><ul><ul><li>Side Effect! </li></ul></ul>
  9. 9. <ul><ul><li>YOU = </li></ul></ul>
  10. 11. <ul><ul><li>Why Ruby? </li></ul></ul>
  11. 12. A great man once said <ul><ul><li>Often people, especially computer engineers, focus on the machines . </li></ul></ul><ul><ul><li>They think, </li></ul></ul><ul><ul><li>“By doing this, the machine will run faster . </li></ul></ul><ul><ul><li>By doing this, the machine will run more effectively . </li></ul></ul><ul><ul><li>By doing this, the machine will something something something ” </li></ul></ul>
  12. 13. They are focusing on machines . But in fact we need to focus on humans , on how humans care about doing programming or operating the application of the machines. We are the masters . They are the slaves .
  13. 15. <ul><ul><li>By doing this, </li></ul></ul><ul><ul><li>the machine will something something something </li></ul></ul>
  14. 16. <ul><ul><li>We are the masters , </li></ul></ul><ul><ul><li>they are the slaves </li></ul></ul><ul><ul><li>Yukihiro Matsumoto </li></ul></ul><ul><ul><li>Creator of Ruby </li></ul></ul>
  15. 17. <ul><ul><li>They are the SLAVES! </li></ul></ul>
  16. 18. <ul><ul><li>and I think we keep forgetting that </li></ul></ul>
  17. 20. <ul><ul><li>Ruby brings... </li></ul></ul>
  18. 21. <ul><ul><li>Large Increase in Productivity </li></ul></ul>
  19. 22. <ul><ul><li>How? </li></ul></ul><ul><ul><li>Non traditional programming style </li></ul></ul>
  20. 23. Everything is an Object string = String .new 5 .times do puts &quot; Hello World &quot; end # Hello World # Hello World # Hello World # Hello World # Hello World
  21. 24. Everything is an Object 1 .upto( 100 ) { | i | puts i } # 1 # 2 # 3 # ... # 100 3.141_592_65 .ceil # 4 2.71828182845905 .floor # 2
  22. 25. Blocks (aka Closures) patients.each do | patient | if patient.ill? physician.examine patient else patient.jump_for_joy! end end
  23. 26. Blocks (aka Closures) hello = Proc .new do | string | puts &quot; Hello #{string.upcase}&quot; end hello.call ' Aizat ' # Hello AIZAT hello.call ' World ' # Hello WORLD
  24. 27. Open Classes class String def sanitize self .gsub( / [^a-z1-9]+ /i , ' _ ' ) end end puts &quot; Ruby gives you alot of $$$ yo! &quot; .sanitize # Ruby_gives_you_alot_of_yo_
  25. 28. Open Classes class Array def rand self [ Kernel ::rand(size)] end end puts %w[ a b c d e f g ] .rand # &quot;e&quot;
  26. 29. Open Classes class Array def shuffle size.downto( 1 ) { | n | push delete_at( Kernel ::rand(n)) } self end end puts %w[ a b c d e f g ] .shuffle.inspect # [&quot;c&quot;, &quot;e&quot;, &quot;f&quot;, &quot;g&quot;, &quot;b&quot;, &quot;d&quot;, &quot;a&quot;]
  27. 30. Open Classes class Numeric def seconds self end def minutes self .seconds * 60 end def hours self .minutes * 60 end def days self .hours * 24 end def weeks self .days * 7 end alias second seconds alias minute minutes alias hour hours alias day days alias week weeks end
  28. 31. Open Classes 1 .second # 1 1 .minute # 60 7.5 .minutes # 450.0 3 .hours # 10800 10.75 hours # 38700 24 .hours # 86400 31 .days # 2678400 51 .weeks # 30844800 365 .days # 31536000 Time .now # Thu May 10 12:10:00 0800 2007 Time .now - 5 .hours # Thu May 10 07:10:00 0800 2007 Time .now - 3 .days # Mon May 07 12:10:00 0800 2007 Time .now - 1 .week # Thu May 03 12:10:00 0800 2007
  29. 32. <ul><ul><li>This is how Rails does its magic </li></ul></ul>
  30. 33. <ul><ul><li>and more... </li></ul></ul>
  31. 34. <ul><ul><li>What is Rails? </li></ul></ul><ul><ul><li>Convention over Configuration </li></ul></ul>
  32. 35. <ul><ul><li>MVC </li></ul></ul><ul><ul><li>Model View Controller </li></ul></ul>
  33. 36. <ul><ul><li>M VC </li></ul></ul><ul><ul><li>Model View Controller </li></ul></ul>
  34. 37. ActiveRecord <ul><li>Object Relation Mapping (ORM) </li></ul><ul><li>Class to Table, Object to Row </li></ul><ul><li>CRUD simple </li></ul><ul><li>Database Agnostic </li></ul>
  35. 38. ActiveRecord
  36. 39. ActiveRecord::Base#find class Patient < ActiveRecord :: Base end Patient .find( 1 ) # SELECT * FROM patients WHERE id = 1 Patient .find_by_name ' Miguel Vega ' # SELECT * FROM patients WHERE name = 'Miguel Vega' Patient .find_by_date_of_birth ' 1986-07-24 ' # SELECT * FROM patients WHERE date_of_birth = '1986-07-24' Patient .find_by_name_and_date_of_birth ' Miguel Vega ' , ' 1986-07-24 ' # SELECT * FROM patients WHERE name = 'Miguel Vega' AND date_of_birth = '1986-07-24'
  37. 40. ActiveRecord::Base#find Patient .count # SELECT COUNT(*) AS count Patient .find :all , :order => ' name DESC ' # SELECT * FROM patients ORDER BY name DESC Patient .find :all , :conditions => [ &quot; name LIKE ? &quot; , &quot; The other guy &quot; ] # SELECT * FROM patients WHERE name = 'The other guy'
  38. 41. Models class Patient < ActiveRecord :: Base end class Encounter < ActiveRecord :: Base end class Physican < ActiveRecord :: Base end
  39. 42. Associations class Patient < ActiveRecord :: Base has_many :encounters has_many :physicans , :through => :encounters end class Encounter < ActiveRecord :: Base belongs_to :patient belongs_to :physician end class Physican < ActiveRecord :: Base has_many :encounters has_many :patients , :through => :encounters end
  40. 43. Smart Defaults class Patient < ActiveRecord :: Base has_many :encounters , :class_name => ' Encounter ' , :foreign_key => ' patient_id ' has_many :physicans , :through => :encounters , :class_name => ' Physician ' , :foreign_key => ' physician_id ' end class Encounter < ActiveRecord :: Base belongs_to :patient , :class_name => ' Patient ' , :foreign_key => ' patient_id ' belongs_to :physician , :class_name => ' Physician ' , :foreign_key => ' physician_id ' end class Physican < ActiveRecord :: Base has_many :encounters , :class_name => ' Encounter ' , :foreign_key => ' patient_id ' has_many :patients , :through => :encounters , :class_name => ' Patient ' , :foreign_key => ' patient_id ' end
  41. 44. Or what people like to call Convention over Configuration
  42. 45. Associations p = Patient .find :first # SELECT * FROM patients LIMIT 1 p.encounters.count # SELECT COUNT(*) AS count FROM encounters WHERE (patient_id = 1) p.encounters.find :condition => [ ' date <= ? ' Time .now - 12 .weeks] # SELECT * FROM encounters WHERE date <= '2007-02-13 16:19:29' AND (patient_id = 1)
  43. 46. Validations class Patient < ActiveRecord :: Base has_many :encounters has_many :physicans , :through => :encounters validates_presence_of :name validates_inclusion_of :gender , :in => [ ' male ' , ' female ' ] validates_email_of :email validates_numericality_of :age validates_confirmation_of :password end
  44. 47. <ul><ul><li>MV C </li></ul></ul><ul><ul><li>Model View Controller </li></ul></ul>
  45. 48. ActionController <ul><li>Separation of business logic and presentation </li></ul><ul><li>Ideally there should be no logic in the view </li></ul>
  46. 49. ActionController class PatientController < ApplicationController def index @patient = Patient .find :first @title = ' Patient Detail ' @homepage_title = &quot; Patient: #{@patient.name}&quot; end end
  47. 50. <ul><ul><li>M V C </li></ul></ul><ul><ul><li>Model View Controller </li></ul></ul>
  48. 51. View < html > < head > < title > <%= @title %> </ title > </ head > < body > < h1 > <%= @homepage_title %> </ h1 > < b > Patient: </ b > < dl > < dt > Name </ dt > < dd > <%= @patient .name %> </ dd > </ dl > <%= render :partial => ' patient_details ' %> </ body > </ html >
  49. 52. <ul><ul><li>Why Rails? </li></ul></ul>
  50. 53. <ul><ul><li>Convention over Configuration </li></ul></ul>
  51. 54. <ul><ul><li>Easy SQL </li></ul></ul><ul><ul><li>ActiveRecord::Base#find </li></ul></ul>
  52. 55. <ul><ul><li>Easy SQL </li></ul></ul><ul><ul><li>Even through associations </li></ul></ul>
  53. 56. <ul><ul><li>RAD/RID </li></ul></ul><ul><ul><li>Rapid Application Development </li></ul></ul><ul><ul><li>Rapid Iterative Development </li></ul></ul>
  54. 57. <ul><ul><li>Testing Framework </li></ul></ul><ul><ul><li>Built in Unit, Function, Integration testing </li></ul></ul>
  55. 58. <ul><ul><li>Awesome Plugin Structure </li></ul></ul>
  56. 59. <ul><ul><li>Simpler and Nicer looking Code </li></ul></ul>
  57. 60. <ul><ul><li>Web 2.0 Ready </li></ul></ul><ul><ul><li>Tagging, Folksonomy, Ajax, REST </li></ul></ul>
  58. 61. <ul><ul><li>Simply RESTful </li></ul></ul>
  59. 62. <ul><ul><li>DRY </li></ul></ul><ul><ul><li>Don't Repeat Yourself </li></ul></ul>
  60. 63. <ul><ul><li>DRY </li></ul></ul><ul><ul><li>Don't Repeat Yourself </li></ul></ul>
  61. 64. DRY <ul><ul><li>Saves time </li></ul></ul><ul><ul><li>Easier to manage </li></ul></ul><ul><ul><li>Reusable Code </li></ul></ul><ul><ul><li>Best of all... </li></ul></ul>
  62. 65. <ul><ul><li>You don't look like a </li></ul></ul><ul><ul><li>code monkey </li></ul></ul>
  63. 66. <ul><ul><li>Most Importantly </li></ul></ul>
  64. 67. <ul><ul><li>Because it's </li></ul></ul><ul><ul><li>FUN </li></ul></ul>
  65. 68. <ul><ul><li>Questions? </li></ul></ul>
  66. 69. <ul><ul><li>Thank you </li></ul></ul><ul><ul><li>amcvega@gmail.com - aizat.faiz@gmail.com </li></ul></ul>Images used are from Tango Desktop Project http://tango.freedesktop.org/

×