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

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 

Recently uploaded (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

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.