SlideShare a Scribd company logo
1 of 69
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/
Who Am I? ,[object Object],[object Object],[object Object],[object Object]
Who Am I? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object]
[object Object]
+ =
[object Object],[object Object],[object Object]
[object Object]
 
[object Object]
A great man once said ,[object Object],[object Object],[object Object],[object Object],[object Object]
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 .
 
[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
[object Object]
[object Object]
 
[object Object]
[object Object]
[object Object],[object Object]
Everything is an Object string =  String .new 5 .times  do puts  " Hello World " end # Hello World # Hello World # Hello World # Hello World # Hello World
Everything is an Object 1 .upto( 100 ) { | i | puts i } # 1 # 2 # 3 # ... # 100 3.141_592_65 .ceil # 4 2.71828182845905 .floor # 2
Blocks (aka Closures) patients.each  do  | patient | if  patient.ill? physician.examine patient else patient.jump_for_joy! end end
Blocks (aka Closures) hello =  Proc .new  do  | string | puts  " Hello  #{string.upcase}" end hello.call  ' Aizat ' # Hello AIZAT hello.call  ' World ' # Hello WORLD
Open Classes class  String def  sanitize self .gsub( / [^a-z1-9]+ /i ,  ' _ ' ) end end puts  " Ruby gives you alot of $$$ yo! " .sanitize # Ruby_gives_you_alot_of_yo_
Open Classes class  Array def  rand self [ Kernel ::rand(size)] end end puts  %w[ a b c d e f g ] .rand # "e"
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 # ["c", "e", "f", "g", "b", "d", "a"]
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
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
[object Object]
[object Object]
[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object]
ActiveRecord ,[object Object],[object Object],[object Object],[object Object]
ActiveRecord
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'
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'
Models class  Patient  <  ActiveRecord :: Base end class  Encounter  <  ActiveRecord :: Base end class  Physican  <  ActiveRecord :: Base end
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
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
Or what people like to call Convention over Configuration
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)
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
[object Object],[object Object]
ActionController ,[object Object],[object Object]
ActionController class  PatientController <  ApplicationController def  index @patient  =  Patient .find  :first @title   =  ' Patient Detail ' @homepage_title  =  &quot; Patient:  #{@patient.name}&quot; end end
[object Object],[object Object]
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 >
[object Object]
[object Object]
[object Object],[object Object]
[object Object],[object Object]
[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object]
[object Object]
[object Object],[object Object]
[object Object]
[object Object],[object Object]
[object Object],[object Object]
DRY ,[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
[object Object]
[object Object],[object Object]
[object Object]
[object Object],[object Object],Images used are from Tango Desktop Project http://tango.freedesktop.org/

More Related Content

What's hot

Django Performance Recipes
Django Performance RecipesDjango Performance Recipes
Django Performance RecipesJon Atkinson
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?Remy Sharp
 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with RubyAnis Ahmad
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Alberto Perdomo
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails PresentationJoost Hietbrink
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and RailsWen-Tien Chang
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby BasicsSHC
 
Introduction to Web Programming with Perl
Introduction to Web Programming with PerlIntroduction to Web Programming with Perl
Introduction to Web Programming with PerlDave Cross
 
Ruby on Rails 2.1 What's New
Ruby on Rails 2.1 What's NewRuby on Rails 2.1 What's New
Ruby on Rails 2.1 What's NewLibin Pan
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionPaul Irish
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012Nicholas Zakas
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hopeMarcus Ramberg
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Doing more with LESS
Doing more with LESSDoing more with LESS
Doing more with LESSjsmith92
 
Realize mais com HTML 5 e CSS 3 - 16 EDTED - RJ
Realize mais com HTML 5 e CSS 3 - 16 EDTED - RJRealize mais com HTML 5 e CSS 3 - 16 EDTED - RJ
Realize mais com HTML 5 e CSS 3 - 16 EDTED - RJLeonardo Balter
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotClouddaoswald
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Anatoly Sharifulin
 

What's hot (20)

Django Performance Recipes
Django Performance RecipesDjango Performance Recipes
Django Performance Recipes
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?
 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with Ruby
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
 
JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
Introduction to Web Programming with Perl
Introduction to Web Programming with PerlIntroduction to Web Programming with Perl
Introduction to Web Programming with Perl
 
Ruby on Rails 2.1 What's New
Ruby on Rails 2.1 What's NewRuby on Rails 2.1 What's New
Ruby on Rails 2.1 What's New
 
Workshop 6: Designer tools
Workshop 6: Designer toolsWorkshop 6: Designer tools
Workshop 6: Designer tools
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Doing more with LESS
Doing more with LESSDoing more with LESS
Doing more with LESS
 
Realize mais com HTML 5 e CSS 3 - 16 EDTED - RJ
Realize mais com HTML 5 e CSS 3 - 16 EDTED - RJRealize mais com HTML 5 e CSS 3 - 16 EDTED - RJ
Realize mais com HTML 5 e CSS 3 - 16 EDTED - RJ
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotCloud
 
Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!Mojolicious. Веб в коробке!
Mojolicious. Веб в коробке!
 

Viewers also liked

ActiveRecord Validations, Season 2
ActiveRecord Validations, Season 2ActiveRecord Validations, Season 2
ActiveRecord Validations, Season 2RORLAB
 
Make your app idea a reality with Ruby On Rails
Make your app idea a reality with Ruby On RailsMake your app idea a reality with Ruby On Rails
Make your app idea a reality with Ruby On RailsNataly Tkachuk
 
ActiveRecord Query Interface (1), Season 1
ActiveRecord Query Interface (1), Season 1ActiveRecord Query Interface (1), Season 1
ActiveRecord Query Interface (1), Season 1RORLAB
 
ActiveWarehouse/ETL - BI & DW for Ruby/Rails
ActiveWarehouse/ETL - BI & DW for Ruby/RailsActiveWarehouse/ETL - BI & DW for Ruby/Rails
ActiveWarehouse/ETL - BI & DW for Ruby/RailsPaul Gallagher
 
6 reasons Jubilee could be a Rubyist's new best friend
6 reasons Jubilee could be a Rubyist's new best friend6 reasons Jubilee could be a Rubyist's new best friend
6 reasons Jubilee could be a Rubyist's new best friendForrest Chang
 
Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsSerge Smetana
 
Neev Expertise in Ruby on Rails (RoR)
Neev Expertise in Ruby on Rails (RoR)Neev Expertise in Ruby on Rails (RoR)
Neev Expertise in Ruby on Rails (RoR)Neev Technologies
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on RailsAgnieszka Figiel
 
From a monolithic Ruby on Rails app to the JVM
From a monolithic  Ruby on Rails app  to the JVMFrom a monolithic  Ruby on Rails app  to the JVM
From a monolithic Ruby on Rails app to the JVMPhil Calçado
 
Design in Tech Report 2017
Design in Tech Report 2017Design in Tech Report 2017
Design in Tech Report 2017John Maeda
 

Viewers also liked (15)

Resume
ResumeResume
Resume
 
Pratap
PratapPratap
Pratap
 
ActiveRecord Validations, Season 2
ActiveRecord Validations, Season 2ActiveRecord Validations, Season 2
ActiveRecord Validations, Season 2
 
Make your app idea a reality with Ruby On Rails
Make your app idea a reality with Ruby On RailsMake your app idea a reality with Ruby On Rails
Make your app idea a reality with Ruby On Rails
 
ActiveRecord Query Interface (1), Season 1
ActiveRecord Query Interface (1), Season 1ActiveRecord Query Interface (1), Season 1
ActiveRecord Query Interface (1), Season 1
 
Rails Performance
Rails PerformanceRails Performance
Rails Performance
 
ActiveWarehouse/ETL - BI & DW for Ruby/Rails
ActiveWarehouse/ETL - BI & DW for Ruby/RailsActiveWarehouse/ETL - BI & DW for Ruby/Rails
ActiveWarehouse/ETL - BI & DW for Ruby/Rails
 
6 reasons Jubilee could be a Rubyist's new best friend
6 reasons Jubilee could be a Rubyist's new best friend6 reasons Jubilee could be a Rubyist's new best friend
6 reasons Jubilee could be a Rubyist's new best friend
 
Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails Applications
 
Neev Expertise in Ruby on Rails (RoR)
Neev Expertise in Ruby on Rails (RoR)Neev Expertise in Ruby on Rails (RoR)
Neev Expertise in Ruby on Rails (RoR)
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Ruby Beyond Rails
Ruby Beyond RailsRuby Beyond Rails
Ruby Beyond Rails
 
Vajidmr resume
Vajidmr resumeVajidmr resume
Vajidmr resume
 
From a monolithic Ruby on Rails app to the JVM
From a monolithic  Ruby on Rails app  to the JVMFrom a monolithic  Ruby on Rails app  to the JVM
From a monolithic Ruby on Rails app to the JVM
 
Design in Tech Report 2017
Design in Tech Report 2017Design in Tech Report 2017
Design in Tech Report 2017
 

Similar to Ruby on Rails

Ods Markup And Tagsets: A Tutorial
Ods Markup And Tagsets: A TutorialOds Markup And Tagsets: A Tutorial
Ods Markup And Tagsets: A Tutorialsimienc
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Coursemussawir20
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kianphelios
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?brynary
 
Advanced Ruby
Advanced RubyAdvanced Ruby
Advanced Rubyalkeshv
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpointwebhostingguy
 
Spring has got me under it’s SpEL
Spring has got me under it’s SpELSpring has got me under it’s SpEL
Spring has got me under it’s SpELEldad Dor
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone InteractivityEric Steele
 
Struts2
Struts2Struts2
Struts2yuvalb
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottO'Reilly Media
 
Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP yucefmerhi
 
Web App Testing With Selenium
Web App Testing With SeleniumWeb App Testing With Selenium
Web App Testing With Seleniumjoaopmaia
 
Perl Teach-In (part 1)
Perl Teach-In (part 1)Perl Teach-In (part 1)
Perl Teach-In (part 1)Dave Cross
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern PerlDave Cross
 
Presentasi Kelompok 25 PW A+B
Presentasi Kelompok 25 PW A+BPresentasi Kelompok 25 PW A+B
Presentasi Kelompok 25 PW A+BHapsoro Permana
 
Tugas pw [kelompok 25]
Tugas pw [kelompok 25]Tugas pw [kelompok 25]
Tugas pw [kelompok 25]guest0ad6a0
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To LampAmzad Hossain
 

Similar to Ruby on Rails (20)

Ods Markup And Tagsets: A Tutorial
Ods Markup And Tagsets: A TutorialOds Markup And Tagsets: A Tutorial
Ods Markup And Tagsets: A Tutorial
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
 
JavaScript Needn't Hurt!
JavaScript Needn't Hurt!JavaScript Needn't Hurt!
JavaScript Needn't Hurt!
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
Advanced Ruby
Advanced RubyAdvanced Ruby
Advanced Ruby
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
Spring has got me under it’s SpEL
Spring has got me under it’s SpELSpring has got me under it’s SpEL
Spring has got me under it’s SpEL
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
Struts2
Struts2Struts2
Struts2
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 
Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP
 
Web App Testing With Selenium
Web App Testing With SeleniumWeb App Testing With Selenium
Web App Testing With Selenium
 
Perl Teach-In (part 1)
Perl Teach-In (part 1)Perl Teach-In (part 1)
Perl Teach-In (part 1)
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern Perl
 
PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
 
Sphinx on Rails
Sphinx on RailsSphinx on Rails
Sphinx on Rails
 
Presentasi Kelompok 25 PW A+B
Presentasi Kelompok 25 PW A+BPresentasi Kelompok 25 PW A+B
Presentasi Kelompok 25 PW A+B
 
Tugas pw [kelompok 25]
Tugas pw [kelompok 25]Tugas pw [kelompok 25]
Tugas pw [kelompok 25]
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To Lamp
 

More from Aizat Faiz

Facebook Social Plugins
Facebook Social PluginsFacebook Social Plugins
Facebook Social PluginsAizat Faiz
 
Location Aware Browsing
Location Aware BrowsingLocation Aware Browsing
Location Aware BrowsingAizat Faiz
 
Beginning WordPress Plugin Development
Beginning WordPress Plugin DevelopmentBeginning WordPress Plugin Development
Beginning WordPress Plugin DevelopmentAizat Faiz
 
The Age of Collaboration
The Age of CollaborationThe Age of Collaboration
The Age of CollaborationAizat Faiz
 
The Future Of Travel
The Future Of TravelThe Future Of Travel
The Future Of TravelAizat Faiz
 
Read Write Culture
Read  Write  CultureRead  Write  Culture
Read Write CultureAizat Faiz
 
Free and Open Source Software Society Malaysia
Free and Open Source Software Society MalaysiaFree and Open Source Software Society Malaysia
Free and Open Source Software Society MalaysiaAizat Faiz
 

More from Aizat Faiz (9)

Facebook Social Plugins
Facebook Social PluginsFacebook Social Plugins
Facebook Social Plugins
 
Location Aware Browsing
Location Aware BrowsingLocation Aware Browsing
Location Aware Browsing
 
Beginning WordPress Plugin Development
Beginning WordPress Plugin DevelopmentBeginning WordPress Plugin Development
Beginning WordPress Plugin Development
 
The Age of Collaboration
The Age of CollaborationThe Age of Collaboration
The Age of Collaboration
 
The Future Of Travel
The Future Of TravelThe Future Of Travel
The Future Of Travel
 
Read Write Culture
Read  Write  CultureRead  Write  Culture
Read Write Culture
 
Jabber Bot
Jabber BotJabber Bot
Jabber Bot
 
Free and Open Source Software Society Malaysia
Free and Open Source Software Society MalaysiaFree and Open Source Software Society Malaysia
Free and Open Source Software Society Malaysia
 
Ruby
RubyRuby
Ruby
 

Recently uploaded

A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 

Recently uploaded (20)

A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 

Ruby on Rails

  • 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.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. + =
  • 8.
  • 9.
  • 10.  
  • 11.
  • 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 .
  • 14.  
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.  
  • 20.
  • 21.
  • 22.
  • 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
  • 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
  • 25. Blocks (aka Closures) patients.each do | patient | if patient.ill? physician.examine patient else patient.jump_for_joy! end end
  • 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
  • 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_
  • 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;
  • 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;]
  • 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
  • 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
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 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'
  • 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'
  • 41. Models class Patient < ActiveRecord :: Base end class Encounter < ActiveRecord :: Base end class Physican < ActiveRecord :: Base end
  • 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
  • 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
  • 44. Or what people like to call Convention over Configuration
  • 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)
  • 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
  • 47.
  • 48.
  • 49. ActionController class PatientController < ApplicationController def index @patient = Patient .find :first @title = ' Patient Detail ' @homepage_title = &quot; Patient: #{@patient.name}&quot; end end
  • 50.
  • 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 >
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.