SlideShare a Scribd company logo
+


Introduzione a Ruby on Rails
        Ing. Danilo Torrisi
        Direttore Tecnico in Priceen


                                        23 Luglio 2012,
                                       Green Hub Catania
Sommario

•       Introduzione
    ‣    Model View Controller
    ‣    REST
•       Concetti Base
    ‣    ActiveRecord
    ‣    Validation
    ‣    Routing
•       Hello World!
Introduzione


Ruby on Rails
Introduzione


     Ruby on Rails

“ is an open-source web framework that’s
  optimized for customer happiness and
         sustainable productivity ”
               rubyonrails.com
Introduzione


Ruby on Rails
Introduzione


         Ruby on Rails

 “Powerful web applications that formerly might
         have taken weeks or months
to develop can be produced in a matter of days”
          Tim O'Reilly, Founder of O'Reilly Media
Chi lo usa?
Chi lo usa?
Introduzione


Ruby on Rails
Introduzione

Ruby       on         Rails
Introduzione

    Ruby               on         Rails


5.times do
  puts "Hello world"
end
Introduzione

    Ruby               on            Rails


5.times do                  def show
  puts "Hello world"          @post = Post.find(params[:id])
end                         end
Ruby


•   Linguaggio interpretato ad oggetti
•   Fortemente dinamico
                                         5.times do
•   Basato sul concetto di blocco          puts "Hello world"
                                         end
•   Tipizzazione dinamica
Ruby


•   Linguaggio interpretato ad oggetti
•   Fortemente dinamico
                                         5.times do
•   Basato sul concetto di blocco          puts "Hello world"
                                         end
•   Tipizzazione dinamica
Ruby


•   Linguaggio interpretato ad oggetti
•   Fortemente dinamico
                                           5.times do
•   Basato sul concetto di blocco            puts "Hello world"
                                           end
•   Tipizzazione dinamica



                   Duck Typing “if it looks like
                   a duck, and quacks like a
                   duck, it must be a duck”
Hello World

5.times do
  puts "Hello world"
end


 =>   “Hello   World”
 =>   “Hello   World”
 =>   “Hello   World”
 =>   “Hello   World”
 =>   “Hello   World”
Hello World

5.times do
  puts "Hello world"
end




  =>   “Hello   World”
  =>   “Hello   World”
  =>   “Hello   World”
  =>   “Hello   World”
  =>   “Hello   World”
Hello World



5.times do
  puts "Hello world"
end
Hello World

 Costante numerica?

5.times do
  puts "Hello world"
end
Hello World

 Costante numerica?

5.times do
  puts "Hello world"
end
Hello World

Istanza della classe Integer

5.times do
  puts "Hello world"
end
Hello World

   Istanza della classe Integer

  5.times do
    puts "Hello world"
  end



Tutto in Ruby è un oggetto
Hello World

    Metodo times della classe Integer

5.times do
  puts "Hello world"
end
Hello World



5.times do
  puts "Hello world"
end
Hello World



5.times do
  puts "Hello world"
end
Hello World



5.times do
  puts "Hello world"
end
Hello World


                       puts   "Hello   world"
5.times do             puts   "Hello   world"
  puts "Hello world"   puts   "Hello   world"
end                    puts   "Hello   world"
                       puts   "Hello   world"
Hello World



5.times do
  puts "Hello world"
end
Hello World



5.times do             5.times do |i|
  puts "Hello world"     puts i.to_s
end                    end
Recap

       5.times do
Ruby     puts "Hello world"
       end
Recap

       5.times do
Ruby     puts "Hello world"
       end




PHP
Recap

       5.times do
Ruby     puts "Hello world"
       end



       for ($i = 1; $i <= 5; $i++) {
PHP        echo "Hello World"
       }
Recap


Ruby


PHP
Recap


Ruby

       if ($users <= 0) {
PHP    }
           echo "No users"
Recap


Ruby   puts "No users" if users <= 0




       if ($users <= 0) {
PHP    }
           echo "No users"
Introduzione

 Ruby                  on            Rails


5.times do                  def show
  puts "Hello world"          @post = Post.find(params[:id])
end                         end
Rails


•       Web Framework Open-Source
•       Paradigma Model View Controller      def show
                                               @post = Post.find(params[:id])
    •    Manutenibilità e riuso del codice   end


•       Paradigma REST
Model View Controller
Model View Controller
<?php

     // Connect to mysql database. Ignore the mysql_select_db for now.
     $db = mysql_connect($hostname,$username,$password)

     // Get all the users data.
     $result = mysql_query("SELECT * FROM users");

     // Display some table..
     echo '<table .....';

     // Now fetch the the array.
     while ($row = mysql_fetch_array($result)) {

         // And display the row.
         echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>';

     }

?>
Model View Controller
<?php

     // Connect to mysql database. Ignore the mysql_select_db for now.
     $db = mysql_connect($hostname,$username,$password)

     // Get all the users data.
     $result = mysql_query("SELECT * FROM users");

     // Display some table..
     echo '<table .....';

     // Now fetch the the array.
     while ($row = mysql_fetch_array($result)) {

         // And display the row.
         echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>';

     }

?>
Model View Controller
<?php

     // Connect to mysql database. Ignore the mysql_select_db for now.
     $db = mysql_connect($hostname,$username,$password)

     // Get all the users data.
     $result = mysql_query("SELECT * FROM users");

     // Display some table..
     echo '<table .....';

     // Now fetch the the array.
     while ($row = mysql_fetch_array($result)) {

         // And display the row.
         echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>';

     }

?>
Model View Controller
<?php

     // Connect to mysql database. Ignore the mysql_select_db for now.
     $db = mysql_connect($hostname,$username,$password)

     // Get all the users data.
     $result = mysql_query("SELECT * FROM users");

     // Display some table..
     echo '<table .....';

     // Now fetch the the array.
     while ($row = mysql_fetch_array($result)) {

         // And display the row.
         echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>';

     }

?>
Model View Controller
<?php

     // Connect to mysql database. Ignore the mysql_select_db for now.
     $db = mysql_connect($hostname,$username,$password)

     // Get all the users data.
     $result = mysql_query("SELECT * FROM users");

     // Display some table..
     echo '<table .....';

     // Now fetch the the array.
     while ($row = mysql_fetch_array($result)) {

         // And display the row.
         echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>';

     }

?>
Model View Controller
<?php

     // Connect to mysql database. Ignore the mysql_select_db for now.
     $db = mysql_connect($hostname,$username,$password)

     // Get all the users data.
     $result = mysql_query("SELECT * FROM users");

     // Display some table..
     echo '<table .....';

     // Now fetch the the array.
     while ($row = mysql_fetch_array($result)) {

         // And display the row.
         echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>';

     }

?>
Model View Controller
<?php

     // Connect to mysql database. Ignore the mysql_select_db for now.
     $db = mysql_connect($hostname,$username,$password)

     // Get all the users data.
     $result = mysql_query("SELECT * FROM users");

     // Display some table..
     echo '<table .....';

     // Now fetch the the array.
     while ($row = mysql_fetch_array($result)) {

         // And display the row.
         echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>';

     }

?>
Model View Controller
<?php

     // Connect to mysql database. Ignore the mysql_select_db for now.
     $db = mysql_connect($hostname,$username,$password)
                                                                         X
     // Get all the users data.
     $result = mysql_query("SELECT * FROM users");

     // Display some table..
     echo '<table .....';

     // Now fetch the the array.
     while ($row = mysql_fetch_array($result)) {

         // And display the row.
         echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>';

     }

?>
Model View Controller
Model View Controller

Configurazione   Connessione      Query
  Database       Database       Database



HTML Layout                   Autorizzazione



Dynamic PHP Data   Sessioni   Gestione Errori
Model View Controller
Model View Controller

         Controller



Model                 View
Model View Controller

         Controller



Model                 View
Model View Controller

         Controller



Model                 View
Model View Controller

         Controller



Model                 View
RES T


•   Architettura distribuita
•   Utilizza protocollo HTTP
•   Ogni elemento è detto risorsa       http://
•   Set di operazioni standard
•   Utilizza i verbi HTTP ovvero GET,
    POST, PUT, DELETE
RES T




http://www.twitter.com/api/
RES T




GET http://www.twitter.com/api/ tweets/ index
RES T




GET http://www.twitter.com/api/ tweets/ index



                               Risorsa
RES T

                                         Azione



GET http://www.twitter.com/api/ tweets/ index



                               Risorsa
RES T
  GET    tweets/ index                    Ritorna tutti i tweet

  GET    tweets/ 1                       Ritorna il tweet id=1

  GET    tweets/ new                  Ritorna un nuovo tweet

 POST    tweets/ create             Aggiungi un nuovo tweet

  GET    tweets/ 1/ edit   Ritorna il tweet id=1 da modificare

  PUT    tweets/ 1/ update             Modifica il tweet id=1

DELETE   tweets/ 1/ destroy            Cancella il tweet id=1
Demo

More Related Content

What's hot

Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
sickill
 
Ruby MVC from scratch with Rack
Ruby MVC from scratch with RackRuby MVC from scratch with Rack
Ruby MVC from scratch with Rack
DonSchado
 
Coffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptCoffeescript: No really, it's just Javascript
Coffeescript: No really, it's just Javascript
Brian Mann
 
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHPDoctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Guilherme Blanco
 
P6 OO vs Moose (&Moo)
P6 OO vs Moose (&Moo)P6 OO vs Moose (&Moo)
P6 OO vs Moose (&Moo)
lichtkind
 
Chloe and the Realtime Web
Chloe and the Realtime WebChloe and the Realtime Web
Chloe and the Realtime Web
Trotter Cashion
 
A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento web
Wallace Reis
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptEddie Kao
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
Wim Godden
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by example
bryanbibat
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
Daniel Cukier
 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScript
Stalin Thangaraj
 
Feb 2018 Spinnaker Meetup Reddit Presentation
Feb 2018 Spinnaker Meetup Reddit PresentationFeb 2018 Spinnaker Meetup Reddit Presentation
Feb 2018 Spinnaker Meetup Reddit Presentation
Edward Ceaser
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
Emanuele DelBono
 
Debugging on rails
Debugging on railsDebugging on rails
Debugging on rails
Mykhaylo Sorochan
 
Rails Girls: Programming, Web Applications and Ruby on Rails
Rails Girls: Programming, Web Applications and Ruby on RailsRails Girls: Programming, Web Applications and Ruby on Rails
Rails Girls: Programming, Web Applications and Ruby on Rails
DonSchado
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIs
Remy Sharp
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
Yoshiki Kurihara
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer Toolbox
Jeff Strauss
 
Migrating PriceChirp to Rails 3.0: The Pain Points
Migrating PriceChirp to Rails 3.0: The Pain PointsMigrating PriceChirp to Rails 3.0: The Pain Points
Migrating PriceChirp to Rails 3.0: The Pain PointsSteven Evatt
 

What's hot (20)

Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Ruby MVC from scratch with Rack
Ruby MVC from scratch with RackRuby MVC from scratch with Rack
Ruby MVC from scratch with Rack
 
Coffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptCoffeescript: No really, it's just Javascript
Coffeescript: No really, it's just Javascript
 
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHPDoctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
 
P6 OO vs Moose (&Moo)
P6 OO vs Moose (&Moo)P6 OO vs Moose (&Moo)
P6 OO vs Moose (&Moo)
 
Chloe and the Realtime Web
Chloe and the Realtime WebChloe and the Realtime Web
Chloe and the Realtime Web
 
A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento web
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by example
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScript
 
Feb 2018 Spinnaker Meetup Reddit Presentation
Feb 2018 Spinnaker Meetup Reddit PresentationFeb 2018 Spinnaker Meetup Reddit Presentation
Feb 2018 Spinnaker Meetup Reddit Presentation
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Debugging on rails
Debugging on railsDebugging on rails
Debugging on rails
 
Rails Girls: Programming, Web Applications and Ruby on Rails
Rails Girls: Programming, Web Applications and Ruby on RailsRails Girls: Programming, Web Applications and Ruby on Rails
Rails Girls: Programming, Web Applications and Ruby on Rails
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIs
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer Toolbox
 
Migrating PriceChirp to Rails 3.0: The Pain Points
Migrating PriceChirp to Rails 3.0: The Pain PointsMigrating PriceChirp to Rails 3.0: The Pain Points
Migrating PriceChirp to Rails 3.0: The Pain Points
 

Similar to Introducing ruby on rails

Modern php
Modern phpModern php
Modern php
Charles Anderson
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
jimbojsb
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
Jean-Baptiste Feldis
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
gicappa
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
Dr Nic Williams
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
arman o
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.jssouridatta
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3
Nate Abele
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
Nick Sieger
 
Pourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirent
Nicolas Ledez
 
Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)
bryanbibat
 
DevOps in PHP environment
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment
Evaldo Felipe
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
rstankov
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
Vagmi Mudumbai
 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionAdam Trachtenberg
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
Lorna Mitchell
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
Alive Kuo
 

Similar to Introducing ruby on rails (20)

Modern php
Modern phpModern php
Modern php
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 
Practical PHP 5.3
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
Pourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirent
 
Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)
 
DevOps in PHP environment
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP Extension
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
Mysqlnd uh
Mysqlnd uhMysqlnd uh
Mysqlnd uh
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 

Introducing ruby on rails

  • 1. + Introduzione a Ruby on Rails Ing. Danilo Torrisi Direttore Tecnico in Priceen 23 Luglio 2012, Green Hub Catania
  • 2. Sommario • Introduzione ‣ Model View Controller ‣ REST • Concetti Base ‣ ActiveRecord ‣ Validation ‣ Routing • Hello World!
  • 4. Introduzione Ruby on Rails “ is an open-source web framework that’s optimized for customer happiness and sustainable productivity ” rubyonrails.com
  • 6. Introduzione Ruby on Rails “Powerful web applications that formerly might have taken weeks or months to develop can be produced in a matter of days” Tim O'Reilly, Founder of O'Reilly Media
  • 10. Introduzione Ruby on Rails
  • 11. Introduzione Ruby on Rails 5.times do puts "Hello world" end
  • 12. Introduzione Ruby on Rails 5.times do def show puts "Hello world" @post = Post.find(params[:id]) end end
  • 13. Ruby • Linguaggio interpretato ad oggetti • Fortemente dinamico 5.times do • Basato sul concetto di blocco puts "Hello world" end • Tipizzazione dinamica
  • 14. Ruby • Linguaggio interpretato ad oggetti • Fortemente dinamico 5.times do • Basato sul concetto di blocco puts "Hello world" end • Tipizzazione dinamica
  • 15. Ruby • Linguaggio interpretato ad oggetti • Fortemente dinamico 5.times do • Basato sul concetto di blocco puts "Hello world" end • Tipizzazione dinamica Duck Typing “if it looks like a duck, and quacks like a duck, it must be a duck”
  • 16. Hello World 5.times do puts "Hello world" end => “Hello World” => “Hello World” => “Hello World” => “Hello World” => “Hello World”
  • 17. Hello World 5.times do puts "Hello world" end => “Hello World” => “Hello World” => “Hello World” => “Hello World” => “Hello World”
  • 18. Hello World 5.times do puts "Hello world" end
  • 19. Hello World Costante numerica? 5.times do puts "Hello world" end
  • 20. Hello World Costante numerica? 5.times do puts "Hello world" end
  • 21. Hello World Istanza della classe Integer 5.times do puts "Hello world" end
  • 22. Hello World Istanza della classe Integer 5.times do puts "Hello world" end Tutto in Ruby è un oggetto
  • 23. Hello World Metodo times della classe Integer 5.times do puts "Hello world" end
  • 24. Hello World 5.times do puts "Hello world" end
  • 25. Hello World 5.times do puts "Hello world" end
  • 26. Hello World 5.times do puts "Hello world" end
  • 27. Hello World puts "Hello world" 5.times do puts "Hello world" puts "Hello world" puts "Hello world" end puts "Hello world" puts "Hello world"
  • 28. Hello World 5.times do puts "Hello world" end
  • 29. Hello World 5.times do 5.times do |i| puts "Hello world" puts i.to_s end end
  • 30. Recap 5.times do Ruby puts "Hello world" end
  • 31. Recap 5.times do Ruby puts "Hello world" end PHP
  • 32. Recap 5.times do Ruby puts "Hello world" end for ($i = 1; $i <= 5; $i++) { PHP echo "Hello World" }
  • 34. Recap Ruby if ($users <= 0) { PHP } echo "No users"
  • 35. Recap Ruby puts "No users" if users <= 0 if ($users <= 0) { PHP } echo "No users"
  • 36. Introduzione Ruby on Rails 5.times do def show puts "Hello world" @post = Post.find(params[:id]) end end
  • 37. Rails • Web Framework Open-Source • Paradigma Model View Controller def show @post = Post.find(params[:id]) • Manutenibilità e riuso del codice end • Paradigma REST
  • 39. Model View Controller <?php // Connect to mysql database. Ignore the mysql_select_db for now. $db = mysql_connect($hostname,$username,$password) // Get all the users data. $result = mysql_query("SELECT * FROM users"); // Display some table.. echo '<table .....'; // Now fetch the the array. while ($row = mysql_fetch_array($result)) { // And display the row. echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>'; } ?>
  • 40. Model View Controller <?php // Connect to mysql database. Ignore the mysql_select_db for now. $db = mysql_connect($hostname,$username,$password) // Get all the users data. $result = mysql_query("SELECT * FROM users"); // Display some table.. echo '<table .....'; // Now fetch the the array. while ($row = mysql_fetch_array($result)) { // And display the row. echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>'; } ?>
  • 41. Model View Controller <?php // Connect to mysql database. Ignore the mysql_select_db for now. $db = mysql_connect($hostname,$username,$password) // Get all the users data. $result = mysql_query("SELECT * FROM users"); // Display some table.. echo '<table .....'; // Now fetch the the array. while ($row = mysql_fetch_array($result)) { // And display the row. echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>'; } ?>
  • 42. Model View Controller <?php // Connect to mysql database. Ignore the mysql_select_db for now. $db = mysql_connect($hostname,$username,$password) // Get all the users data. $result = mysql_query("SELECT * FROM users"); // Display some table.. echo '<table .....'; // Now fetch the the array. while ($row = mysql_fetch_array($result)) { // And display the row. echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>'; } ?>
  • 43. Model View Controller <?php // Connect to mysql database. Ignore the mysql_select_db for now. $db = mysql_connect($hostname,$username,$password) // Get all the users data. $result = mysql_query("SELECT * FROM users"); // Display some table.. echo '<table .....'; // Now fetch the the array. while ($row = mysql_fetch_array($result)) { // And display the row. echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>'; } ?>
  • 44. Model View Controller <?php // Connect to mysql database. Ignore the mysql_select_db for now. $db = mysql_connect($hostname,$username,$password) // Get all the users data. $result = mysql_query("SELECT * FROM users"); // Display some table.. echo '<table .....'; // Now fetch the the array. while ($row = mysql_fetch_array($result)) { // And display the row. echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>'; } ?>
  • 45. Model View Controller <?php // Connect to mysql database. Ignore the mysql_select_db for now. $db = mysql_connect($hostname,$username,$password) // Get all the users data. $result = mysql_query("SELECT * FROM users"); // Display some table.. echo '<table .....'; // Now fetch the the array. while ($row = mysql_fetch_array($result)) { // And display the row. echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>'; } ?>
  • 46. Model View Controller <?php // Connect to mysql database. Ignore the mysql_select_db for now. $db = mysql_connect($hostname,$username,$password) X // Get all the users data. $result = mysql_query("SELECT * FROM users"); // Display some table.. echo '<table .....'; // Now fetch the the array. while ($row = mysql_fetch_array($result)) { // And display the row. echo 'ID: '.$row{'id'}.' Name: '.$row{'name'}.'</br>'; } ?>
  • 48. Model View Controller Configurazione Connessione Query Database Database Database HTML Layout Autorizzazione Dynamic PHP Data Sessioni Gestione Errori
  • 50. Model View Controller Controller Model View
  • 51. Model View Controller Controller Model View
  • 52. Model View Controller Controller Model View
  • 53. Model View Controller Controller Model View
  • 54. RES T • Architettura distribuita • Utilizza protocollo HTTP • Ogni elemento è detto risorsa http:// • Set di operazioni standard • Utilizza i verbi HTTP ovvero GET, POST, PUT, DELETE
  • 57. RES T GET http://www.twitter.com/api/ tweets/ index Risorsa
  • 58. RES T Azione GET http://www.twitter.com/api/ tweets/ index Risorsa
  • 59. RES T GET tweets/ index Ritorna tutti i tweet GET tweets/ 1 Ritorna il tweet id=1 GET tweets/ new Ritorna un nuovo tweet POST tweets/ create Aggiungi un nuovo tweet GET tweets/ 1/ edit Ritorna il tweet id=1 da modificare PUT tweets/ 1/ update Modifica il tweet id=1 DELETE tweets/ 1/ destroy Cancella il tweet id=1
  • 60. Demo