SlideShare a Scribd company logo
1 of 60
Ruby on Rails
A Complete Introduction
Good Morning
                                Welcome to Carsonified

                .
         a ve..
  is is D
Th


                    Hi there!
Who am I?
                         Adam Cooke


       I work at...               which is part of




                 ...
I have developed

                                                     and lots of other stuf
                                                                            f
... and you are?
So, the plan...
Introduction
The Rails Basics
Building a Blogging Engine
More Advancement
Testing
When things go wrong!
Deployments
Finishing up
re   ...
                         a re he
                   you

1   Introduction            What is Rails?
                            The MVC Pattern
                            Ruby Overview
                            RubyGems
                            Installing Rails
                            Components of Rails
What is Rails?
David Heinemeier Hansson
                  aka DHH
          & the res
                    t of the R
                               ails Core
                                         Team
[title]
 [sub title]
Who’s using Rails?
The MVC Pattern
   Model-view-controller
Controller




Model                View
Rails routing happens here
                      Controller




      Model                                       View


Database   Resource
                                   Return to the browser
Ruby
Simple
Easy to write

          Elegant
Everything is an object
 Module                String
            Hash

    Array                 Proc
              Fixnum
 Symbol                 Numeric
class Numeric
    def plus(x)
        self.+(x)
    end
end

y = 5.plus 10 #=> 15
5.times { puts “Hello!” }
Ruby Objects
Variables                                  For example

Any plain, lowercase word                  a, my_variable and banana10


       out...
Try it


>> blah
NameError: undefined local variable or method `blah'

>>    string = “Hello World!”
=>    “Hello World!”
>>    string
=>    “Hello World!”
Numbers                           For example

Integers - positive or negative   1, 41231 and
                                  -68835

       out...
Try it

>>    5 + 10
=>    15
>>    10 * 10
=>    100
>>    3.1 + 1.55
=>    4.65
Strings                         For example

Anything surrounded by quotes   “Dave”, “123”and “My name
                                is...”

       out...
Try it

>>    my_quote = “My name is Dave!”
=>    “My name is Dave!”
>>    my_quote
=>    “My name is Dave!”
Symbols                               For example

Start with a colon, look like words   :a, :first_name and :abc123


       out...
Try it

>>    my_symbol = :complete
=>    :complete
>>    my_symbol
=>    :complete
Constants                                      For example

Like variables, with a capital                Hash, Monkey and Dave_The_Frog


       out...
Try it

>> MyMonkey = “James”
                                               Yo
                                                 us
=> “James”                                              hou
                                                              ldn
                                                                    ’t
>> MyMonkey = “Michael”                                                  ch
                                                                           an
(irb):1: warning: already initialized constant MyMonkey                         ge
                                                                                   it,a
=> “Michael”                                                                            ft
                                                                                          er
                                                                                             it   ’s
                                                                                                       be
                                                                                                         en
                                                                                                              se
                                                                                                                t
Methods            For example

The verbs!         say_hello and close


       out...
Try it

>> def say_hello
>> puts “Hello!”
>> end
>> say_hello
Hello!
=> nil
Method Args               For example

Passing data to methods   say_hello(name)


       out...
Try it

>> def say_hello(name, age)
>> puts “Hello #{name}!”
>> puts “You are #{age}!”
>> end
>> say_hello(‘Keir’, 45)
Hello Keir!
You are 45!
=> nil
Method Args               For example

Passing data to methods   say_hello(name)


       out...
Try it

>> def say_hello(name, age)
>> puts “Hello #{name}!”
>> puts “You are #{age}!”
>> end
>> say_hello(‘Keir’, 45)
Hello Keir!
You are 30!
=> nil
Arrays                                 For example

A list surrounded by square brackets   [1,2,3] and [‘A’,‘B’,‘C’]


       out...
Try it

>>    a = [1,2,3,4,5]
=>    [1,2,3,4,5]
>>    a
=>    [1,2,3,4,5]
>>    a[1]
=>    2
>>    a[1, 3]
=>    [2,3,4]
Hashes                              For example

A list surrounded by curly braces   {1=>2, 3=>4} and
                                    {:a => ‘Ant’,
                                     :b => ‘Badger’}
       out...
Try it

>>    h = {:a => ‘Good’, :b => ‘Bad’}
=>    {:a => ‘Good’, :b => ‘Bad’}
>>    h(:a)
=>    ‘Good’
>>    h.keys
=>    [:a, :b]
>>    h.values
=>    [‘Good’, ‘Bad’]
The Big One...
Classes
Anatomy of a class
class Person
    attr_accessor :first_name, :last_name
end

             p = Person.new
             p.first_name = ‘Dave’
             p.last_name = ‘Jones’
             p.first_name #=> “Dave”
class Person
   attr_accessor :first_name, :last_name

      def initialize(first, last)
          self.first_name = first
          self.last_name = last
      end

      def full_name
         [self.first_name, self.last_name].join(“ ”)
      end
end
                p = Person.new(‘Dave’, ‘Jones’)
                p.first_name #=> “Dave”
                p.last_name   #=> “Jones”
                p.full_name   #=> “Dave Jones”
Ruby Gems
Your Ruby Package Manager
user@dev01:~#                          gem list
*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (2.1.0, 2.0.2, 1.3.6, 1.3.3)
actionpack (2.1.0, 2.0.2, 1.13.6, 1.13.3)
actionwebservice (1.2.6, 1.2.3)
activerecord (2.1.0, 2.0.2, 1.15.6, 1.15.3)
activeresource (2.1.0, 2.0.2)
activesupport (2.1.0, 2.0.2, 1.4.4, 1.4.2)
acts_as_ferret (0.4.1)
aws-s3 (0.4.0)
builder (2.1.2)
capistrano (2.3.0, 1.4.0)
cgi_multipart_eof_fix (2.5.0, 2.2)
cheat (1.2.1)
chronic (0.2.3)
codebase-gem (1.0.3)
daemons (1.0.10, 1.0.9, 1.0.7)
dnssd (0.6.0)
erubis (2.5.0)
gem install rails
gem remove rails
gem update rails
Useful Gems
                   The Rails Gems

rails              actionmailer
                    actionpack
mongrel_cluster    activerecord
capistrano        activeresource
mysql             activesupport
                       rails
                       rake
Components of Rails
        Action Pack
      Active Support
       Active Record
       Action Mailer
      Active Resource
Action Pack
All the view & controller logic
Active Support
Collection of utility classes and library extensions
Active Record
 The object relationship mapper
Action Mailer
   E-Mail Delivery
1   Introduction   What is Rails?
                   The MVC Pattern
                   Ruby Overview
                   RubyGems
                   Installing Rails
                   Components of Rails          ...
                                        are here
                                  you
re   ...
                          a re he
                    you

2   The Rails Basics Development Tools & Environment
                     Generating an Application
                     The Directory Structure
                     Starting up the app
                     “RESTful Rails”
                     Routing & URLs
Active Resource
  Connect with REST web services
Editors & IDEs
Database Browsers
Generating an App.
    rails my_app_name

rails my_app_name -d mysql
app      Contains the majority of your application specific code
config   Application config - routing map, database config etc...
db       Database schema, SQLite database files & migrations
doc      Generated HTML API documentation for the application or Rails
lib      Application-specific libraries - anything which doesn’t belong in app/
log      Log files and web server PID files
public   Your webserver document root - contains images, JS, CSS etc...
script   Rails helper scripts for automation and generation
test     Unit & functional tests along with any fixtures
tmp      Application specific temporary files
vendor   External libraries used in the application - gems, plugins etc...
app      controllers     Controllers named as posts_controller.rb
config   helpers         View helpers named as posts_helper.rb
db       models          Models named as post.rb
doc      views           Controller template files named as
                         posts/index.html.erb for the
lib                      PostsController#index action
log      views/layouts   Layout template files in the format of
                         application.html.erb for an
public                   application wide layout or posts.html.erb
script                   for controller specific layouts.
test
tmp
vendor
Starting the App
   Running a Local Webserver

   script/server
“RESTful Rails”
 Representational State Transfer
HTTP Methods
GET     POST     PUT      DELETE


READ    CREATE   UPDATE   DESTROY
Resource: Customer

/customers             GET   index   POST   create




/customers/1234        GET   show    PUT    update   DELETE   destroy



/customers/new         GET   new




/customers/1234/edit   GET   edit
Routing & URLs
    config/routes.rb
domain.com/my-page
map.connect “my-page”, :controller => “pages”, :action => “my”


domain.com/customers (as a resource)
map.resources :customers


domain.com (the root domain)
map.root :controller => “pages”, :action => “homepage”


domain.com/pages/about
map.connect “pages/:action”, :controller => “pages”


domain.com/pages/about/123
map.connect “:controller/:action/:id”
Named Routes
    rake routes
URL Helpers can use named routes (link_to, form for...)
<%=link_to ‘Homepage’, root_path%>


<%=link_to ‘Customer List’, customers_path%>


<%=link_to ‘View this Customer’, customer_path(1234)%>


<%=link_to ‘Edit this Customer’, edit_customer_path(1234)%>


<%form_for :customer, :url => customers_path do |f|...%>


                                           A POST request - so will call the ‘create’ action
2   The Rails Basics Development Tools & Environment
                     Generating an Application
                     The Directory Structure
                     Starting up the app
                     “RESTful Rails”
                     Routing & URLs
                                                 ...
                                         are here
                                   you

More Related Content

What's hot (20)

Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Introduction to react js
Introduction to react jsIntroduction to react js
Introduction to react js
 
Javascript
JavascriptJavascript
Javascript
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
 
React js
React jsReact js
React js
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
Clean code
Clean code Clean code
Clean code
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
React js
React jsReact js
React js
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
 
Javascript
JavascriptJavascript
Javascript
 
Ajax and Jquery
Ajax and JqueryAjax and Jquery
Ajax and Jquery
 
Reactjs
ReactjsReactjs
Reactjs
 

Similar to Ruby on Rails Presentation

Ruby from zero to hero
Ruby from zero to heroRuby from zero to hero
Ruby from zero to heroDiego Lemos
 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScriptStalin Thangaraj
 
Fog City Ruby - Triple Equals Black Magic with speaker notes
Fog City Ruby - Triple Equals Black Magic with speaker notesFog City Ruby - Triple Equals Black Magic with speaker notes
Fog City Ruby - Triple Equals Black Magic with speaker notesBrandon Weaver
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Henry S
 
Test First Teaching
Test First TeachingTest First Teaching
Test First TeachingSarah Allen
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technologyppparthpatel123
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to RubyRyan Cross
 
Ruby: Beyond the Basics
Ruby: Beyond the BasicsRuby: Beyond the Basics
Ruby: Beyond the BasicsMichael Koby
 
Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)Gautam Rege
 
Ruby — An introduction
Ruby — An introductionRuby — An introduction
Ruby — An introductionGonçalo Silva
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Wen-Tien Chang
 
Playfulness at Work
Playfulness at WorkPlayfulness at Work
Playfulness at WorkErin Dees
 
A linguagem de programação Ruby - Robson "Duda" Sejan Soares Dornelles
A linguagem de programação Ruby - Robson "Duda" Sejan Soares DornellesA linguagem de programação Ruby - Robson "Duda" Sejan Soares Dornelles
A linguagem de programação Ruby - Robson "Duda" Sejan Soares DornellesTchelinux
 
Ruby Programming Language
Ruby Programming LanguageRuby Programming Language
Ruby Programming LanguageDuda Dornelles
 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyVysakh Sreenivasan
 

Similar to Ruby on Rails Presentation (20)

Ruby from zero to hero
Ruby from zero to heroRuby from zero to hero
Ruby from zero to hero
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScript
 
Fog City Ruby - Triple Equals Black Magic with speaker notes
Fog City Ruby - Triple Equals Black Magic with speaker notesFog City Ruby - Triple Equals Black Magic with speaker notes
Fog City Ruby - Triple Equals Black Magic with speaker notes
 
Learning Ruby
Learning RubyLearning Ruby
Learning Ruby
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
 
Test First Teaching
Test First TeachingTest First Teaching
Test First Teaching
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Ruby: Beyond the Basics
Ruby: Beyond the BasicsRuby: Beyond the Basics
Ruby: Beyond the Basics
 
Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)
 
Ruby
RubyRuby
Ruby
 
Ruby — An introduction
Ruby — An introductionRuby — An introduction
Ruby — An introduction
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
 
Playfulness at Work
Playfulness at WorkPlayfulness at Work
Playfulness at Work
 
A linguagem de programação Ruby - Robson "Duda" Sejan Soares Dornelles
A linguagem de programação Ruby - Robson "Duda" Sejan Soares DornellesA linguagem de programação Ruby - Robson "Duda" Sejan Soares Dornelles
A linguagem de programação Ruby - Robson "Duda" Sejan Soares Dornelles
 
Ruby Programming Language
Ruby Programming LanguageRuby Programming Language
Ruby Programming Language
 
Ruby
RubyRuby
Ruby
 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced Ruby
 
Rails OO views
Rails OO viewsRails OO views
Rails OO views
 

Recently uploaded

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 

Recently uploaded (20)

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 

Ruby on Rails Presentation

  • 1. Ruby on Rails A Complete Introduction
  • 2. Good Morning Welcome to Carsonified . a ve.. is is D Th Hi there!
  • 3. Who am I? Adam Cooke I work at... which is part of ... I have developed and lots of other stuf f
  • 4. ... and you are?
  • 6. Introduction The Rails Basics Building a Blogging Engine More Advancement Testing When things go wrong! Deployments Finishing up
  • 7. re ... a re he you 1 Introduction What is Rails? The MVC Pattern Ruby Overview RubyGems Installing Rails Components of Rails
  • 9. David Heinemeier Hansson aka DHH & the res t of the R ails Core Team
  • 12.
  • 13. The MVC Pattern Model-view-controller
  • 15. Rails routing happens here Controller Model View Database Resource Return to the browser
  • 16. Ruby
  • 18. Everything is an object Module String Hash Array Proc Fixnum Symbol Numeric
  • 19. class Numeric def plus(x) self.+(x) end end y = 5.plus 10 #=> 15
  • 20. 5.times { puts “Hello!” }
  • 22. Variables For example Any plain, lowercase word a, my_variable and banana10 out... Try it >> blah NameError: undefined local variable or method `blah' >> string = “Hello World!” => “Hello World!” >> string => “Hello World!”
  • 23. Numbers For example Integers - positive or negative 1, 41231 and -68835 out... Try it >> 5 + 10 => 15 >> 10 * 10 => 100 >> 3.1 + 1.55 => 4.65
  • 24. Strings For example Anything surrounded by quotes “Dave”, “123”and “My name is...” out... Try it >> my_quote = “My name is Dave!” => “My name is Dave!” >> my_quote => “My name is Dave!”
  • 25. Symbols For example Start with a colon, look like words :a, :first_name and :abc123 out... Try it >> my_symbol = :complete => :complete >> my_symbol => :complete
  • 26. Constants For example Like variables, with a capital Hash, Monkey and Dave_The_Frog out... Try it >> MyMonkey = “James” Yo us => “James” hou ldn ’t >> MyMonkey = “Michael” ch an (irb):1: warning: already initialized constant MyMonkey ge it,a => “Michael” ft er it ’s be en se t
  • 27. Methods For example The verbs! say_hello and close out... Try it >> def say_hello >> puts “Hello!” >> end >> say_hello Hello! => nil
  • 28. Method Args For example Passing data to methods say_hello(name) out... Try it >> def say_hello(name, age) >> puts “Hello #{name}!” >> puts “You are #{age}!” >> end >> say_hello(‘Keir’, 45) Hello Keir! You are 45! => nil
  • 29. Method Args For example Passing data to methods say_hello(name) out... Try it >> def say_hello(name, age) >> puts “Hello #{name}!” >> puts “You are #{age}!” >> end >> say_hello(‘Keir’, 45) Hello Keir! You are 30! => nil
  • 30. Arrays For example A list surrounded by square brackets [1,2,3] and [‘A’,‘B’,‘C’] out... Try it >> a = [1,2,3,4,5] => [1,2,3,4,5] >> a => [1,2,3,4,5] >> a[1] => 2 >> a[1, 3] => [2,3,4]
  • 31. Hashes For example A list surrounded by curly braces {1=>2, 3=>4} and {:a => ‘Ant’, :b => ‘Badger’} out... Try it >> h = {:a => ‘Good’, :b => ‘Bad’} => {:a => ‘Good’, :b => ‘Bad’} >> h(:a) => ‘Good’ >> h.keys => [:a, :b] >> h.values => [‘Good’, ‘Bad’]
  • 33. Classes Anatomy of a class class Person attr_accessor :first_name, :last_name end p = Person.new p.first_name = ‘Dave’ p.last_name = ‘Jones’ p.first_name #=> “Dave”
  • 34. class Person attr_accessor :first_name, :last_name def initialize(first, last) self.first_name = first self.last_name = last end def full_name [self.first_name, self.last_name].join(“ ”) end end p = Person.new(‘Dave’, ‘Jones’) p.first_name #=> “Dave” p.last_name #=> “Jones” p.full_name #=> “Dave Jones”
  • 35. Ruby Gems Your Ruby Package Manager
  • 36. user@dev01:~# gem list *** LOCAL GEMS *** abstract (1.0.0) actionmailer (2.1.0, 2.0.2, 1.3.6, 1.3.3) actionpack (2.1.0, 2.0.2, 1.13.6, 1.13.3) actionwebservice (1.2.6, 1.2.3) activerecord (2.1.0, 2.0.2, 1.15.6, 1.15.3) activeresource (2.1.0, 2.0.2) activesupport (2.1.0, 2.0.2, 1.4.4, 1.4.2) acts_as_ferret (0.4.1) aws-s3 (0.4.0) builder (2.1.2) capistrano (2.3.0, 1.4.0) cgi_multipart_eof_fix (2.5.0, 2.2) cheat (1.2.1) chronic (0.2.3) codebase-gem (1.0.3) daemons (1.0.10, 1.0.9, 1.0.7) dnssd (0.6.0) erubis (2.5.0)
  • 37. gem install rails gem remove rails gem update rails
  • 38. Useful Gems The Rails Gems rails actionmailer actionpack mongrel_cluster activerecord capistrano activeresource mysql activesupport rails rake
  • 39. Components of Rails Action Pack Active Support Active Record Action Mailer Active Resource
  • 40. Action Pack All the view & controller logic
  • 41. Active Support Collection of utility classes and library extensions
  • 42. Active Record The object relationship mapper
  • 43. Action Mailer E-Mail Delivery
  • 44. 1 Introduction What is Rails? The MVC Pattern Ruby Overview RubyGems Installing Rails Components of Rails ... are here you
  • 45. re ... a re he you 2 The Rails Basics Development Tools & Environment Generating an Application The Directory Structure Starting up the app “RESTful Rails” Routing & URLs
  • 46. Active Resource Connect with REST web services
  • 49. Generating an App. rails my_app_name rails my_app_name -d mysql
  • 50. app Contains the majority of your application specific code config Application config - routing map, database config etc... db Database schema, SQLite database files & migrations doc Generated HTML API documentation for the application or Rails lib Application-specific libraries - anything which doesn’t belong in app/ log Log files and web server PID files public Your webserver document root - contains images, JS, CSS etc... script Rails helper scripts for automation and generation test Unit & functional tests along with any fixtures tmp Application specific temporary files vendor External libraries used in the application - gems, plugins etc...
  • 51. app controllers Controllers named as posts_controller.rb config helpers View helpers named as posts_helper.rb db models Models named as post.rb doc views Controller template files named as posts/index.html.erb for the lib PostsController#index action log views/layouts Layout template files in the format of application.html.erb for an public application wide layout or posts.html.erb script for controller specific layouts. test tmp vendor
  • 52. Starting the App Running a Local Webserver script/server
  • 54. HTTP Methods GET POST PUT DELETE READ CREATE UPDATE DESTROY
  • 55. Resource: Customer /customers GET index POST create /customers/1234 GET show PUT update DELETE destroy /customers/new GET new /customers/1234/edit GET edit
  • 56. Routing & URLs config/routes.rb
  • 57. domain.com/my-page map.connect “my-page”, :controller => “pages”, :action => “my” domain.com/customers (as a resource) map.resources :customers domain.com (the root domain) map.root :controller => “pages”, :action => “homepage” domain.com/pages/about map.connect “pages/:action”, :controller => “pages” domain.com/pages/about/123 map.connect “:controller/:action/:id”
  • 58. Named Routes rake routes
  • 59. URL Helpers can use named routes (link_to, form for...) <%=link_to ‘Homepage’, root_path%> <%=link_to ‘Customer List’, customers_path%> <%=link_to ‘View this Customer’, customer_path(1234)%> <%=link_to ‘Edit this Customer’, edit_customer_path(1234)%> <%form_for :customer, :url => customers_path do |f|...%> A POST request - so will call the ‘create’ action
  • 60. 2 The Rails Basics Development Tools & Environment Generating an Application The Directory Structure Starting up the app “RESTful Rails” Routing & URLs ... are here you