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

Ruby Programming Language - Introduction
Ruby Programming Language - IntroductionRuby Programming Language - Introduction
Ruby Programming Language - IntroductionKwangshin Oh
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data TypesTareq Hasan
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial之宇 趙
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby BasicsSHC
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arraysHassan Dar
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Aaron Gustafson
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScriptRavi Bhadauria
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - ObjectsWebStackAcademy
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS Ganesh Kondal
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation platico_dev
 
Strings in Java
Strings in Java Strings in Java
Strings in Java Hitesh-Java
 

What's hot (20)

Ruby Programming Language - Introduction
Ruby Programming Language - IntroductionRuby Programming Language - Introduction
Ruby Programming Language - Introduction
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Java script
Java scriptJava script
Java script
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
Js ppt
Js pptJs ppt
Js ppt
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
 
Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]Fundamental JavaScript [UTC, March 2014]
Fundamental JavaScript [UTC, March 2014]
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScript
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Javascript
JavascriptJavascript
Javascript
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Spring boot
Spring bootSpring boot
Spring boot
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Strings in Java
Strings in Java Strings in Java
Strings in Java
 

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
 
Ruby Programming Language
Ruby Programming LanguageRuby Programming Language
Ruby Programming LanguageDuda Dornelles
 
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
 
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
 
Ruby Programming Language
Ruby Programming LanguageRuby Programming Language
Ruby Programming Language
 
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
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

What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 

Recently uploaded (20)

What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 

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