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

What's hot (20)

Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
 
Ruby On Rails Basics
Ruby On Rails BasicsRuby On Rails Basics
Ruby On Rails Basics
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Java file
Java fileJava file
Java file
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 

Similar to Ruby on Rails Presentation

Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
ppparthpatel123
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
Wen-Tien Chang
 

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

Recently uploaded (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

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