SlideShare a Scribd company logo
1 of 54
Ruby   Ruby on Rails               Demo               Summary   JRuby




                           Ruby on Rails

                            Tristan Bigourdan
                              David Alphen

                         Sales & e-Commerce Platform
                       Server Architecture & Frameworks


                             Internship 2007
Ruby            Ruby on Rails    Demo   Summary   JRuby




Focus
       1   Ruby
             History
             In Brief
             Language Tour
       2   Ruby on Rails
             Introduction
             Rails MVC
             Components
       3   Demo
       4   Summary
             Strengths and Weaknesses
             Key benefits
       5   JRuby
             JRuby
             JRuby on Rails
             Future of JRuby
Ruby            Ruby on Rails    Demo   Summary   JRuby




Focus
       1   Ruby
             History
             In Brief
             Language Tour
       2   Ruby on Rails
             Introduction
             Rails MVC
             Components
       3   Demo
       4   Summary
             Strengths and Weaknesses
             Key benefits
       5   JRuby
             JRuby
             JRuby on Rails
             Future of JRuby
Ruby            Ruby on Rails    Demo   Summary   JRuby




Focus
       1   Ruby
             History
             In Brief
             Language Tour
       2   Ruby on Rails
             Introduction
             Rails MVC
             Components
       3   Demo
       4   Summary
             Strengths and Weaknesses
             Key benefits
       5   JRuby
             JRuby
             JRuby on Rails
             Future of JRuby
Ruby            Ruby on Rails    Demo   Summary   JRuby




Focus
       1   Ruby
             History
             In Brief
             Language Tour
       2   Ruby on Rails
             Introduction
             Rails MVC
             Components
       3   Demo
       4   Summary
             Strengths and Weaknesses
             Key benefits
       5   JRuby
             JRuby
             JRuby on Rails
             Future of JRuby
Ruby            Ruby on Rails    Demo   Summary   JRuby




Focus
       1   Ruby
             History
             In Brief
             Language Tour
       2   Ruby on Rails
             Introduction
             Rails MVC
             Components
       3   Demo
       4   Summary
             Strengths and Weaknesses
             Key benefits
       5   JRuby
             JRuby
             JRuby on Rails
             Future of JRuby
Ruby                Ruby on Rails       Demo           Summary     JRuby


History




          History
              Developed by Yukihiri Matsumoto a.k.a "Matz"
              Inspired by Smalltalk, Python and Perl
              1993 : Creation
              1995 : First release
              2000 : USA adoption (books, documentation)
              March 2007 : release 1.8.6
              Famous in Japan and USA (especially through rails)
              Collaborative platform : http ://rubyforge.org
Ruby                Ruby on Rails       Demo            Summary     JRuby


In Brief




           Main features
               Ruby is a dynamic, object oriented and interpreted
               language written in C and open source.
               Focus on simplicity, productivity and "fun"
Ruby                  Ruby on Rails       Demo              Summary   JRuby


Language Tour


Everything is Object


                Pure Object Oriented language
                Absolutely everything is an object
                nil.class                            => NilClass
                //.class                             => Regexp
                "Amadeus".length                     => 7
                3.times { |i| puts "Number #{i}" }
                                                     => Number 1
                                                     => Number 2
                                                     => Number 3
Ruby                 Ruby on Rails         Demo            Summary            JRuby


Language Tour


Dynamic Typing

                Dynamically typed language
                    No need to declare variables
                Duck Typing
                    "If the object quacks and walks like a duck then it’s a duck"
                    The type of an object is defined by what that object can do

       Example
       class NerdConnexion
          def talk
            "I’m a nerd 2.0"
          end
       end
       nerd = NerdConnexion.new
       nerd.respond_to ?( :talk) => true
Ruby                 Ruby on Rails         Demo            Summary            JRuby


Language Tour


Dynamic Typing

                Dynamically typed language
                    No need to declare variables
                Duck Typing
                    "If the object quacks and walks like a duck then it’s a duck"
                    The type of an object is defined by what that object can do

       Example
       class NerdConnexion
          def talk
            "I’m a nerd 2.0"
          end
       end
       nerd = NerdConnexion.new
       nerd.respond_to ?( :talk) => true
Ruby                 Ruby on Rails         Demo            Summary            JRuby


Language Tour


Dynamic Typing

                Dynamically typed language
                    No need to declare variables
                Duck Typing
                    "If the object quacks and walks like a duck then it’s a duck"
                    The type of an object is defined by what that object can do

       Example
       class NerdConnexion
          def talk
            "I’m a nerd 2.0"
          end
       end
       nerd = NerdConnexion.new
       nerd.respond_to ?( :talk) => true
Ruby                 Ruby on Rails      Demo             Summary   JRuby


Language Tour


Metaprogramming


                Create code dynamically
                Modify existing classes
                    add/alias/remove/replace methods
                    include a Module, Mixin
                    add instance/class variable
                method_missing() const_missing()
                Dynamic finders
                    find_all_by_name_and_age(’john’,42)
                    find_or_create
                Query objects about their methods
                    obj.methods
Ruby                 Ruby on Rails   Demo   Summary   JRuby


Language Tour


Design Pattern 1/3




       Core Implementation
                Singleton
                Factory
                Observer
Ruby            Ruby on Rails    Demo         Summary         JRuby


Language Tour


Design Pattern 2/3

       Personal Implementation
       class MySingleton
          private_class_method :new
          @@class_variable = nil
          def MySingleton.create
             @@class_variable = new unless @@class_variable
             @@class_variable
          end
       end

       Problem
       Not thread safe
Ruby            Ruby on Rails    Demo         Summary         JRuby


Language Tour


Design Pattern 2/3

       Personal Implementation
       class MySingleton
          private_class_method :new
          @@class_variable = nil
          def MySingleton.create
             @@class_variable = new unless @@class_variable
             @@class_variable
          end
       end

       Problem
       Not thread safe
Ruby            Ruby on Rails   Demo   Summary   JRuby


Language Tour


Design Pattern 3/3

       Core Implementation
       require singleton
       class CoreSingleton
          attr_accessor :new
          include Singleton
       end

       Result
       Thread safe
Ruby            Ruby on Rails   Demo   Summary   JRuby


Language Tour


Design Pattern 3/3

       Core Implementation
       require singleton
       class CoreSingleton
          attr_accessor :new
          include Singleton
       end

       Result
       Thread safe
Ruby                    Ruby on Rails    Demo          Summary             JRuby


Language Tour


Single Inheritance


   Code example                         Mixins
   module Shape
      attr_accessor :type
                                            A module included in a class
      attr_accessor :color
      def initialize(type, color)
         @type = type
         @color = color
      end
   end
   class Square
      include Shape
      attr_accessor :side
      def perimeter
         side * 4
      end
   end
   s = Square.new "Square", "Red"
   s.side = 6

   class « s
      def area
          side * side
      end
   end
Ruby                  Ruby on Rails    Demo            Summary   JRuby


Language Tour


Containers


       Block, Iterator, Array
                {} or do . . .end
                Syntactical sugar

       Example
       tab = [1,2,3,4,5,6,7,8,9]
       tab.each do
         |i| print i
       end
       %w(un dos tres).each {|p| print p}
        [1,2,3,4,5,6,7,8,9].each_index {|i| print i}
Ruby              Ruby on Rails        Demo   Summary   JRuby


Language Tour


Containers



       Block, Iterator, Hash
       my_hash = {
          :key1 => "value1",
          :key2 => "value2"
       }
       def aff
         yield.each_key {|val| print val}
       end
       aff {my_hash}
Ruby                Ruby on Rails        Demo          Summary           JRuby


Introduction




       What is Ruby on Rails
               Creator : David Heinemeier Hansson
               First stable version : 12.2005
               March 07 : rails 1.2.3
               MIT Licence
               Rails is a full stack web-application framework following the
               MVC pattern which includes :
               an ORM package ActiveRecord,
               a template engine,
               a controller framework,
               everything needed to develop web-apps that can run on
               CGI, FastCGI, and mod_ruby.
Ruby                Ruby on Rails       Demo               Summary   JRuby


Introduction




       Principles
           1   Convention over configuration
                   avoid XML configuration
                   can be overridden
           2   DRY : Don’t Repeat Yourself
                   Reduce code redundancy
           3   Agile development environment
                   No recompile, deploy, restart cycles
                   Simple tools to generate code quickly
                   Testing built into framework
Ruby                Ruby on Rails      Demo           Summary        JRuby


Introduction




       Why Ruby on Rails ?
               Created while solving a problem from the real world
               Agile Development
               Develop fast web applications
               Simplicity
               Web 2.0
Ruby                 Ruby on Rails        Demo          Summary   JRuby


Introduction




       Why Ruby ?
               Ruby’s Metaprogramming
               Ruby’s Librairies
               Ruby’s simplicity and efficiency
               Rails is written in Ruby
               Share parent child relationships
               Ruby is the father, Rails is the child
               Same conventions
               Develop faster
               Better productivity
Ruby           Ruby on Rails   Demo   Summary   JRuby


Rails MVC



       The Rails MVC
Ruby               Ruby on Rails    Demo          Summary          JRuby


Components




   Components                      Reminder
         Active Record             Rails is a Full Stack Web Framework.
         Action Pack
         Scaffolding
         Database Versioning
         Ajax Integration
         Tests
         Active Support
         Action Mailer
         Action Web Services
         Plugins
         Scripts
         ...
Ruby               Ruby on Rails    Demo          Summary          JRuby


Components




   Components                      Reminder
         Active Record             Rails is a Full Stack Web Framework.
         Action Pack
         Scaffolding
         Database Versioning
         Ajax Integration
         Tests
         Active Support
         Action Mailer
         Action Web Services
         Plugins
         Scripts
         ...
Ruby              Ruby on Rails      Demo         Summary        JRuby


Components


Active Record 1/3


             Based on a design pattern defined by Martin Fowler
             ORM layer supplied with Rails
             No more SQL
             Tables map to classes
             Rows map to objects
             Columns map to attributes
             Relies on convention
             Validation
             Transaction
Ruby               Ruby on Rails       Demo            Summary         JRuby


Components


Active Record 2/3


       Conventions
        1    Table names
                  Plural form of the Class
                  Class Flight => flights
                  Class MyFlight => my_flights
        2    Turn this off
                  in config/environment.rb :
                  ActiveRecord : :Base.pluralize_table_names = false
                  in the model :
                  class Flight < ActiveRecord : :Base
                    set_table_name "db_flights"
                  end
Ruby              Ruby on Rails        Demo            Summary   JRuby


Components


Active Record 3/3


       Conventions
        1    Primary keys
                 Default name : id
                 Can be manually defined
                 class Flight < ActiveRecord : :Base
                  set_primary_key "flight_id"
                 end
        2    Foreign keys
                 By default [singular_name_id]
                  flight_id
                 No foreign key constraints => Use SQL
Ruby                 Ruby on Rails   Demo   Summary   JRuby


Components


Action Pack

       Action Controller
            Routing
             Cookies and Sessions
             Filters
             Caching

       Action View
            Helpers
             rhtml
             rjs
             rxml
             layouts, partials
Ruby                 Ruby on Rails   Demo   Summary   JRuby


Components


Action Pack

       Action Controller
            Routing
             Cookies and Sessions
             Filters
             Caching

       Action View
            Helpers
             rhtml
             rjs
             rxml
             layouts, partials
Ruby              Ruby on Rails     Demo   Summary   JRuby


Components




       Scaffolding
             Manipulate the model
             CRUD
             Administration
Ruby              Ruby on Rails        Demo       Summary      JRuby


Components




       Database Versioning
             Starting point of the application
             Evolves with the application
             Data and Schema migrations
             Database Independant
             Constraints and Stored procedures not supported
             => Native SQL
             Caution : rollback
Ruby               Ruby on Rails        Demo         Summary   JRuby


Components


Web 2.0



       Ajax
              Prototype
                  Simplifies the use of Javascript
              Script.aculo.us
                  Built on top of Prototype
                  Autocompletion, Drag and Drop,
                  Visual effects, Observers, . . .
Ruby          Ruby on Rails   Demo   Summary   JRuby




       DEMO
Ruby                  Ruby on Rails   Demo             Summary        JRuby


Strengths and Weaknesses




   Strengths                                 Weaknesses
          Conventions                           Maturity (Specifications,
          Feedback loop                         Documentation)
          Active Community                       Independant groups of
                                                 developers
          Full stack framework
                                                 Connection pooling, JMS
          Ruby’s strengths
                                                 Performance
          Ajax
                                                 Deployment on the
                                                 Windows platform
                                                 New way of developping,
                                                 thinking
                                                 IDE
Ruby                  Ruby on Rails   Demo             Summary        JRuby


Strengths and Weaknesses




   Strengths                                 Weaknesses
          Conventions                           Maturity (Specifications,
          Feedback loop                         Documentation)
          Active Community                       Independant groups of
                                                 developers
          Full stack framework
                                                 Connection pooling, JMS
          Ruby’s strengths
                                                 Performance
          Ajax
                                                 Deployment on the
                                                 Windows platform
                                                 New way of developping,
                                                 thinking
                                                 IDE
Ruby               Ruby on Rails      Demo   Summary   JRuby


Key benefits




       Conclusion
          Fast development
              Better productivity
              Reduce costs
              Write code, not configuration
Ruby            Ruby on Rails      Demo            Summary         JRuby


JRuby




        JRuby
           100% pure java implementation of the Ruby interpreter
           Created in 2002
           Open source, many active contributors
           Two main contributors recently hired by Sun Microsystems
           to work full time
           Aims at compatibility with current Ruby version
           Current version : 1.0
Ruby             Ruby on Rails     Demo           Summary           JRuby


JRuby


Java from JRuby 1/2




        Using Java from JRuby
            Import and use java packages and classes within JRuby
            scripts
            Subclass java classes with JRuby classes
            Implement java interfaces with JRuby classes
Ruby              Ruby on Rails        Demo         Summary   JRuby


JRuby


Java from JRuby 2/2


        Power of java technology with Ruby syntax
          set = java.util.TreeSet.new
          set.add "foo"
          set.add "Bar"
          set.add "Baz"
          set.each do |v| puts "value : #{v}" end

          list = java.util.ArrayList.new
          list « 1
          list « 3
          list « 2
          list.sort
Ruby              Ruby on Rails       Demo             Summary           JRuby


JRuby


JRuby from Java 1/2



        Call from java applications to JRuby scripts through JSR 223
            JSR-223 : simple and small API that specifies the contract
            for communicating with a scripting language from java and
            vise versa
            API introduced in java SE 6 in package javax.script
            Allows to :
                Call scripts, script functions, methods and objects from Java
                Access java objects and classes from scripts
Ruby             Ruby on Rails      Demo          Summary         JRuby


JRuby


JRuby from Java 2/2


        Integrate Java with JRuby using JSR-223
          //Create a JRuby engine
          ScriptEngine jrEngine = factory.getEngineByName("jruby") ;
          // Make available a java object to JRuby
          jrEngine.put("javaobject", "dummy_string") ;
          // Print dummy_string from JRuby code
          try {
             jrEngine.eval("puts(javaobject)") ;
          }catch (ScriptException exception) {
             exception.printStackTrace() ;
          }
Ruby             Ruby on Rails          Demo      Summary        JRuby


JRuby


Why JRuby ?

        JRuby over Ruby
            Compilation
            Better performance and scalability than Ruby
            (eg : native threading)
            Native unicode support
            Java API + java libraries

        JRuby over Java
            Ruby language : dynamic typing, blocks, modules,
            metoprogramming
            Ruby applications : Ruby on Rails, Rake, Raven etc
Ruby             Ruby on Rails          Demo      Summary        JRuby


JRuby


Why JRuby ?

        JRuby over Ruby
            Compilation
            Better performance and scalability than Ruby
            (eg : native threading)
            Native unicode support
            Java API + java libraries

        JRuby over Java
            Ruby language : dynamic typing, blocks, modules,
            metoprogramming
            Ruby applications : Ruby on Rails, Rake, Raven etc
Ruby                  Ruby on Rails        Demo             Summary           JRuby


JRuby on Rails




       Jruby on Rails
                 Part of JRuby project
                 Brings power and functionality of Java to Ruby on Rails :
                     Call scripts, script functions, methods and objects from Java
                     Deployment of ROR apps to JEE application servers
                     (switch framework VS switch whole architecture)
                     Java scalability (eg : database pooling)
                     Java libraries
                     Integration with java legacy apps
Ruby                  Ruby on Rails        Demo             Summary           JRuby


JRuby on Rails




       Jruby on Rails
                 Part of JRuby project
                 Brings power and functionality of Java to Ruby on Rails :
                     Call scripts, script functions, methods and objects from Java
                     Deployment of ROR apps to JEE application servers
                     (switch framework VS switch whole architecture)
                     Java scalability (eg : database pooling)
                     Java libraries
                     Integration with java legacy apps
Ruby               Ruby on Rails        Demo         Summary          JRuby


Future of JRuby




       JRuby Future ?
              RoR lack of maturity
              JRuby : bring power of JVMs, JEE application servers and
              libraries to RoR
                  => lower barrier of entry
              Glassfish V3 (Sun JEE application server) will allows to run
              other containers than JEE : RoR, PHP etc
Ruby              Ruby on Rails   Demo   Summary   JRuby


Future of JRuby




       Q&A
       Thank you
Ruby              Ruby on Rails               Demo               Summary   JRuby


Future of JRuby




                                      Ruby on Rails

                                       Tristan Bigourdan
                                         David Alphen

                                    Sales & e-Commerce Platform
                                  Server Architecture & Frameworks


                                        Internship 2007
Appendix


Bibliographie


More Information I

                Dave Thomas
                Programming Ruby 2nd edition.
                Pragmatic Programmers 2005.
                David Heinemeier Hansson
                Agile Web Development with Rails 2nd edition.
                Pragmatic Programmers 2007.
                Memo
                http ://www.zenspider.com/Languages/Ruby/QuickRef.html
                Good memo.
                Ruby Doc
                http ://www.ruby-doc.org
                Standard and Core Librairies APIs.
Appendix


Bibliographie


More Information II


                Ruby Garden
                http ://www.rubygarden.org
                Ruby tutorials, wiki, . . .
                Ruby On Rails
                http ://www.rubyonrails.org
                RoR doc, tutorials, wiki, . . .
                JRuby
                http ://www.jruby.org
                JRuby doc, tutorials, wiki, . . .

More Related Content

What's hot

Ro r trilogy-part-1
Ro r trilogy-part-1Ro r trilogy-part-1
Ro r trilogy-part-1sdeconf
 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projectsjazzman1980
 
Invoke dynamic your api to hotspot
Invoke dynamic your api to hotspotInvoke dynamic your api to hotspot
Invoke dynamic your api to hotspotBoundary
 
Comparing implementations of the actor model
Comparing implementations of the actor modelComparing implementations of the actor model
Comparing implementations of the actor modelJim Roepcke
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# DevelopersCory Foy
 
Ola Bini Evolving The Java Platform
Ola Bini Evolving The Java PlatformOla Bini Evolving The Java Platform
Ola Bini Evolving The Java Platformdeimos
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvmdeimos
 
Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)Kiran Jonnalagadda
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRubyelliando dias
 
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 JRubyNick Sieger
 
Pré Descobrimento Do Brasil
Pré Descobrimento Do BrasilPré Descobrimento Do Brasil
Pré Descobrimento Do Brasilecsette
 
I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?sbjug
 
You need to extend your models? EMF Facet vs. EMF Profiles
You need to extend your models? EMF Facet vs. EMF ProfilesYou need to extend your models? EMF Facet vs. EMF Profiles
You need to extend your models? EMF Facet vs. EMF ProfilesPhilip Langer
 
Understanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesUnderstanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesRafael Luque Leiva
 
JVM Interop - Functional Conf 2019
JVM Interop - Functional Conf 2019JVM Interop - Functional Conf 2019
JVM Interop - Functional Conf 2019Ravindra Jaju
 

What's hot (18)

Ro r trilogy-part-1
Ro r trilogy-part-1Ro r trilogy-part-1
Ro r trilogy-part-1
 
roofimon@njug5
roofimon@njug5roofimon@njug5
roofimon@njug5
 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projects
 
Invoke dynamic your api to hotspot
Invoke dynamic your api to hotspotInvoke dynamic your api to hotspot
Invoke dynamic your api to hotspot
 
Comparing implementations of the actor model
Comparing implementations of the actor modelComparing implementations of the actor model
Comparing implementations of the actor model
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# Developers
 
Ola Bini Evolving The Java Platform
Ola Bini Evolving The Java PlatformOla Bini Evolving The Java Platform
Ola Bini Evolving The Java Platform
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvm
 
Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)Python's dynamic nature (rough slides, November 2004)
Python's dynamic nature (rough slides, November 2004)
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
 
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
 
Rjb
RjbRjb
Rjb
 
Pré Descobrimento Do Brasil
Pré Descobrimento Do BrasilPré Descobrimento Do Brasil
Pré Descobrimento Do Brasil
 
Traits composition
Traits compositionTraits composition
Traits composition
 
I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?
 
You need to extend your models? EMF Facet vs. EMF Profiles
You need to extend your models? EMF Facet vs. EMF ProfilesYou need to extend your models? EMF Facet vs. EMF Profiles
You need to extend your models? EMF Facet vs. EMF Profiles
 
Understanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesUnderstanding Java Dynamic Proxies
Understanding Java Dynamic Proxies
 
JVM Interop - Functional Conf 2019
JVM Interop - Functional Conf 2019JVM Interop - Functional Conf 2019
JVM Interop - Functional Conf 2019
 

Viewers also liked

Sector hidrocarburos en Bolivia
Sector hidrocarburos en BoliviaSector hidrocarburos en Bolivia
Sector hidrocarburos en Boliviaguestf886d8
 
What's New in C++ 11/14?
What's New in C++ 11/14?What's New in C++ 11/14?
What's New in C++ 11/14?Dina Goldshtein
 
Future Of Ruby And Rails
Future Of Ruby And RailsFuture Of Ruby And Rails
Future Of Ruby And RailsMatt Aimonetti
 
C++14 - Modern Programming for Demanding Times
C++14 - Modern Programming for Demanding TimesC++14 - Modern Programming for Demanding Times
C++14 - Modern Programming for Demanding TimesCarlos Miguel Ferreira
 
Elements of C++11
Elements of C++11Elements of C++11
Elements of C++11Uilian Ries
 
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Yasuko Ohba
 
Ruby On Rails Basics
Ruby On Rails BasicsRuby On Rails Basics
Ruby On Rails BasicsAmit Solanki
 
Modern C++ Lunch and Learn
Modern C++ Lunch and LearnModern C++ Lunch and Learn
Modern C++ Lunch and LearnPaul Irwin
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by examplebryanbibat
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Railsrstankov
 
Ruby On Rails Overview
Ruby On Rails OverviewRuby On Rails Overview
Ruby On Rails Overviewjonkinney
 
Explotacion de hidrocarburos
Explotacion de hidrocarburosExplotacion de hidrocarburos
Explotacion de hidrocarburosEthel Vandergriff
 
Ruby & Rails Error Handling
Ruby & Rails Error HandlingRuby & Rails Error Handling
Ruby & Rails Error HandlingSimon Maynard
 

Viewers also liked (20)

Petroleo 2015
Petroleo 2015Petroleo 2015
Petroleo 2015
 
Sector hidrocarburos en Bolivia
Sector hidrocarburos en BoliviaSector hidrocarburos en Bolivia
Sector hidrocarburos en Bolivia
 
What's New in C++ 11/14?
What's New in C++ 11/14?What's New in C++ 11/14?
What's New in C++ 11/14?
 
Future Of Ruby And Rails
Future Of Ruby And RailsFuture Of Ruby And Rails
Future Of Ruby And Rails
 
Modern C++
Modern C++Modern C++
Modern C++
 
C++14 - Modern Programming for Demanding Times
C++14 - Modern Programming for Demanding TimesC++14 - Modern Programming for Demanding Times
C++14 - Modern Programming for Demanding Times
 
Hidrocarburos ypfb
Hidrocarburos ypfbHidrocarburos ypfb
Hidrocarburos ypfb
 
Elements of C++11
Elements of C++11Elements of C++11
Elements of C++11
 
C++11 - STL Additions
C++11 - STL AdditionsC++11 - STL Additions
C++11 - STL Additions
 
C++ Core Guidelines
C++ Core GuidelinesC++ Core Guidelines
C++ Core Guidelines
 
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
 
More functional C++14
More functional C++14More functional C++14
More functional C++14
 
Ruby On Rails Basics
Ruby On Rails BasicsRuby On Rails Basics
Ruby On Rails Basics
 
Modern C++ Lunch and Learn
Modern C++ Lunch and LearnModern C++ Lunch and Learn
Modern C++ Lunch and Learn
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by example
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Ruby On Rails Overview
Ruby On Rails OverviewRuby On Rails Overview
Ruby On Rails Overview
 
Explotacion de hidrocarburos
Explotacion de hidrocarburosExplotacion de hidrocarburos
Explotacion de hidrocarburos
 
Ruby & Rails Error Handling
Ruby & Rails Error HandlingRuby & Rails Error Handling
Ruby & Rails Error Handling
 

Similar to Ruby On Rails pizza training

Similar to Ruby On Rails pizza training (20)

JRuby - Programmer's Best Friend on JVM
JRuby - Programmer's Best Friend on JVMJRuby - Programmer's Best Friend on JVM
JRuby - Programmer's Best Friend on JVM
 
Intro for RoR
Intro for RoRIntro for RoR
Intro for RoR
 
Ruby Metaprogramming 08
Ruby Metaprogramming 08Ruby Metaprogramming 08
Ruby Metaprogramming 08
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008
 
Bitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRubyBitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRuby
 
XRuby_Overview_20070831
XRuby_Overview_20070831XRuby_Overview_20070831
XRuby_Overview_20070831
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Ruby Introduction
Ruby IntroductionRuby Introduction
Ruby Introduction
 
P4 P Update January 2009
P4 P Update January 2009P4 P Update January 2009
P4 P Update January 2009
 
Ebay News 2000 10 19 Earnings
Ebay News 2000 10 19 EarningsEbay News 2000 10 19 Earnings
Ebay News 2000 10 19 Earnings
 
Ebay News 2001 4 19 Earnings
Ebay News 2001 4 19 EarningsEbay News 2001 4 19 Earnings
Ebay News 2001 4 19 Earnings
 
Devoxx%202008%20Tutorial
Devoxx%202008%20TutorialDevoxx%202008%20Tutorial
Devoxx%202008%20Tutorial
 
Devoxx%202008%20Tutorial
Devoxx%202008%20TutorialDevoxx%202008%20Tutorial
Devoxx%202008%20Tutorial
 
Java, Ruby & Rails
Java, Ruby & RailsJava, Ruby & Rails
Java, Ruby & Rails
 
Ruby an overall approach
Ruby an overall approachRuby an overall approach
Ruby an overall approach
 
Ruby and Rails short motivation
Ruby and Rails short motivationRuby and Rails short motivation
Ruby and Rails short motivation
 
Ruby
RubyRuby
Ruby
 
Practical JRuby
Practical JRubyPractical JRuby
Practical JRuby
 

Ruby On Rails pizza training

  • 1. Ruby Ruby on Rails Demo Summary JRuby Ruby on Rails Tristan Bigourdan David Alphen Sales & e-Commerce Platform Server Architecture & Frameworks Internship 2007
  • 2. Ruby Ruby on Rails Demo Summary JRuby Focus 1 Ruby History In Brief Language Tour 2 Ruby on Rails Introduction Rails MVC Components 3 Demo 4 Summary Strengths and Weaknesses Key benefits 5 JRuby JRuby JRuby on Rails Future of JRuby
  • 3. Ruby Ruby on Rails Demo Summary JRuby Focus 1 Ruby History In Brief Language Tour 2 Ruby on Rails Introduction Rails MVC Components 3 Demo 4 Summary Strengths and Weaknesses Key benefits 5 JRuby JRuby JRuby on Rails Future of JRuby
  • 4. Ruby Ruby on Rails Demo Summary JRuby Focus 1 Ruby History In Brief Language Tour 2 Ruby on Rails Introduction Rails MVC Components 3 Demo 4 Summary Strengths and Weaknesses Key benefits 5 JRuby JRuby JRuby on Rails Future of JRuby
  • 5. Ruby Ruby on Rails Demo Summary JRuby Focus 1 Ruby History In Brief Language Tour 2 Ruby on Rails Introduction Rails MVC Components 3 Demo 4 Summary Strengths and Weaknesses Key benefits 5 JRuby JRuby JRuby on Rails Future of JRuby
  • 6. Ruby Ruby on Rails Demo Summary JRuby Focus 1 Ruby History In Brief Language Tour 2 Ruby on Rails Introduction Rails MVC Components 3 Demo 4 Summary Strengths and Weaknesses Key benefits 5 JRuby JRuby JRuby on Rails Future of JRuby
  • 7. Ruby Ruby on Rails Demo Summary JRuby History History Developed by Yukihiri Matsumoto a.k.a "Matz" Inspired by Smalltalk, Python and Perl 1993 : Creation 1995 : First release 2000 : USA adoption (books, documentation) March 2007 : release 1.8.6 Famous in Japan and USA (especially through rails) Collaborative platform : http ://rubyforge.org
  • 8. Ruby Ruby on Rails Demo Summary JRuby In Brief Main features Ruby is a dynamic, object oriented and interpreted language written in C and open source. Focus on simplicity, productivity and "fun"
  • 9. Ruby Ruby on Rails Demo Summary JRuby Language Tour Everything is Object Pure Object Oriented language Absolutely everything is an object nil.class => NilClass //.class => Regexp "Amadeus".length => 7 3.times { |i| puts "Number #{i}" } => Number 1 => Number 2 => Number 3
  • 10. Ruby Ruby on Rails Demo Summary JRuby Language Tour Dynamic Typing Dynamically typed language No need to declare variables Duck Typing "If the object quacks and walks like a duck then it’s a duck" The type of an object is defined by what that object can do Example class NerdConnexion def talk "I’m a nerd 2.0" end end nerd = NerdConnexion.new nerd.respond_to ?( :talk) => true
  • 11. Ruby Ruby on Rails Demo Summary JRuby Language Tour Dynamic Typing Dynamically typed language No need to declare variables Duck Typing "If the object quacks and walks like a duck then it’s a duck" The type of an object is defined by what that object can do Example class NerdConnexion def talk "I’m a nerd 2.0" end end nerd = NerdConnexion.new nerd.respond_to ?( :talk) => true
  • 12. Ruby Ruby on Rails Demo Summary JRuby Language Tour Dynamic Typing Dynamically typed language No need to declare variables Duck Typing "If the object quacks and walks like a duck then it’s a duck" The type of an object is defined by what that object can do Example class NerdConnexion def talk "I’m a nerd 2.0" end end nerd = NerdConnexion.new nerd.respond_to ?( :talk) => true
  • 13. Ruby Ruby on Rails Demo Summary JRuby Language Tour Metaprogramming Create code dynamically Modify existing classes add/alias/remove/replace methods include a Module, Mixin add instance/class variable method_missing() const_missing() Dynamic finders find_all_by_name_and_age(’john’,42) find_or_create Query objects about their methods obj.methods
  • 14. Ruby Ruby on Rails Demo Summary JRuby Language Tour Design Pattern 1/3 Core Implementation Singleton Factory Observer
  • 15. Ruby Ruby on Rails Demo Summary JRuby Language Tour Design Pattern 2/3 Personal Implementation class MySingleton private_class_method :new @@class_variable = nil def MySingleton.create @@class_variable = new unless @@class_variable @@class_variable end end Problem Not thread safe
  • 16. Ruby Ruby on Rails Demo Summary JRuby Language Tour Design Pattern 2/3 Personal Implementation class MySingleton private_class_method :new @@class_variable = nil def MySingleton.create @@class_variable = new unless @@class_variable @@class_variable end end Problem Not thread safe
  • 17. Ruby Ruby on Rails Demo Summary JRuby Language Tour Design Pattern 3/3 Core Implementation require singleton class CoreSingleton attr_accessor :new include Singleton end Result Thread safe
  • 18. Ruby Ruby on Rails Demo Summary JRuby Language Tour Design Pattern 3/3 Core Implementation require singleton class CoreSingleton attr_accessor :new include Singleton end Result Thread safe
  • 19. Ruby Ruby on Rails Demo Summary JRuby Language Tour Single Inheritance Code example Mixins module Shape attr_accessor :type A module included in a class attr_accessor :color def initialize(type, color) @type = type @color = color end end class Square include Shape attr_accessor :side def perimeter side * 4 end end s = Square.new "Square", "Red" s.side = 6 class « s def area side * side end end
  • 20. Ruby Ruby on Rails Demo Summary JRuby Language Tour Containers Block, Iterator, Array {} or do . . .end Syntactical sugar Example tab = [1,2,3,4,5,6,7,8,9] tab.each do |i| print i end %w(un dos tres).each {|p| print p} [1,2,3,4,5,6,7,8,9].each_index {|i| print i}
  • 21. Ruby Ruby on Rails Demo Summary JRuby Language Tour Containers Block, Iterator, Hash my_hash = { :key1 => "value1", :key2 => "value2" } def aff yield.each_key {|val| print val} end aff {my_hash}
  • 22. Ruby Ruby on Rails Demo Summary JRuby Introduction What is Ruby on Rails Creator : David Heinemeier Hansson First stable version : 12.2005 March 07 : rails 1.2.3 MIT Licence Rails is a full stack web-application framework following the MVC pattern which includes : an ORM package ActiveRecord, a template engine, a controller framework, everything needed to develop web-apps that can run on CGI, FastCGI, and mod_ruby.
  • 23. Ruby Ruby on Rails Demo Summary JRuby Introduction Principles 1 Convention over configuration avoid XML configuration can be overridden 2 DRY : Don’t Repeat Yourself Reduce code redundancy 3 Agile development environment No recompile, deploy, restart cycles Simple tools to generate code quickly Testing built into framework
  • 24. Ruby Ruby on Rails Demo Summary JRuby Introduction Why Ruby on Rails ? Created while solving a problem from the real world Agile Development Develop fast web applications Simplicity Web 2.0
  • 25. Ruby Ruby on Rails Demo Summary JRuby Introduction Why Ruby ? Ruby’s Metaprogramming Ruby’s Librairies Ruby’s simplicity and efficiency Rails is written in Ruby Share parent child relationships Ruby is the father, Rails is the child Same conventions Develop faster Better productivity
  • 26. Ruby Ruby on Rails Demo Summary JRuby Rails MVC The Rails MVC
  • 27. Ruby Ruby on Rails Demo Summary JRuby Components Components Reminder Active Record Rails is a Full Stack Web Framework. Action Pack Scaffolding Database Versioning Ajax Integration Tests Active Support Action Mailer Action Web Services Plugins Scripts ...
  • 28. Ruby Ruby on Rails Demo Summary JRuby Components Components Reminder Active Record Rails is a Full Stack Web Framework. Action Pack Scaffolding Database Versioning Ajax Integration Tests Active Support Action Mailer Action Web Services Plugins Scripts ...
  • 29. Ruby Ruby on Rails Demo Summary JRuby Components Active Record 1/3 Based on a design pattern defined by Martin Fowler ORM layer supplied with Rails No more SQL Tables map to classes Rows map to objects Columns map to attributes Relies on convention Validation Transaction
  • 30. Ruby Ruby on Rails Demo Summary JRuby Components Active Record 2/3 Conventions 1 Table names Plural form of the Class Class Flight => flights Class MyFlight => my_flights 2 Turn this off in config/environment.rb : ActiveRecord : :Base.pluralize_table_names = false in the model : class Flight < ActiveRecord : :Base set_table_name "db_flights" end
  • 31. Ruby Ruby on Rails Demo Summary JRuby Components Active Record 3/3 Conventions 1 Primary keys Default name : id Can be manually defined class Flight < ActiveRecord : :Base set_primary_key "flight_id" end 2 Foreign keys By default [singular_name_id] flight_id No foreign key constraints => Use SQL
  • 32. Ruby Ruby on Rails Demo Summary JRuby Components Action Pack Action Controller Routing Cookies and Sessions Filters Caching Action View Helpers rhtml rjs rxml layouts, partials
  • 33. Ruby Ruby on Rails Demo Summary JRuby Components Action Pack Action Controller Routing Cookies and Sessions Filters Caching Action View Helpers rhtml rjs rxml layouts, partials
  • 34. Ruby Ruby on Rails Demo Summary JRuby Components Scaffolding Manipulate the model CRUD Administration
  • 35. Ruby Ruby on Rails Demo Summary JRuby Components Database Versioning Starting point of the application Evolves with the application Data and Schema migrations Database Independant Constraints and Stored procedures not supported => Native SQL Caution : rollback
  • 36. Ruby Ruby on Rails Demo Summary JRuby Components Web 2.0 Ajax Prototype Simplifies the use of Javascript Script.aculo.us Built on top of Prototype Autocompletion, Drag and Drop, Visual effects, Observers, . . .
  • 37. Ruby Ruby on Rails Demo Summary JRuby DEMO
  • 38. Ruby Ruby on Rails Demo Summary JRuby Strengths and Weaknesses Strengths Weaknesses Conventions Maturity (Specifications, Feedback loop Documentation) Active Community Independant groups of developers Full stack framework Connection pooling, JMS Ruby’s strengths Performance Ajax Deployment on the Windows platform New way of developping, thinking IDE
  • 39. Ruby Ruby on Rails Demo Summary JRuby Strengths and Weaknesses Strengths Weaknesses Conventions Maturity (Specifications, Feedback loop Documentation) Active Community Independant groups of developers Full stack framework Connection pooling, JMS Ruby’s strengths Performance Ajax Deployment on the Windows platform New way of developping, thinking IDE
  • 40. Ruby Ruby on Rails Demo Summary JRuby Key benefits Conclusion Fast development Better productivity Reduce costs Write code, not configuration
  • 41. Ruby Ruby on Rails Demo Summary JRuby JRuby JRuby 100% pure java implementation of the Ruby interpreter Created in 2002 Open source, many active contributors Two main contributors recently hired by Sun Microsystems to work full time Aims at compatibility with current Ruby version Current version : 1.0
  • 42. Ruby Ruby on Rails Demo Summary JRuby JRuby Java from JRuby 1/2 Using Java from JRuby Import and use java packages and classes within JRuby scripts Subclass java classes with JRuby classes Implement java interfaces with JRuby classes
  • 43. Ruby Ruby on Rails Demo Summary JRuby JRuby Java from JRuby 2/2 Power of java technology with Ruby syntax set = java.util.TreeSet.new set.add "foo" set.add "Bar" set.add "Baz" set.each do |v| puts "value : #{v}" end list = java.util.ArrayList.new list « 1 list « 3 list « 2 list.sort
  • 44. Ruby Ruby on Rails Demo Summary JRuby JRuby JRuby from Java 1/2 Call from java applications to JRuby scripts through JSR 223 JSR-223 : simple and small API that specifies the contract for communicating with a scripting language from java and vise versa API introduced in java SE 6 in package javax.script Allows to : Call scripts, script functions, methods and objects from Java Access java objects and classes from scripts
  • 45. Ruby Ruby on Rails Demo Summary JRuby JRuby JRuby from Java 2/2 Integrate Java with JRuby using JSR-223 //Create a JRuby engine ScriptEngine jrEngine = factory.getEngineByName("jruby") ; // Make available a java object to JRuby jrEngine.put("javaobject", "dummy_string") ; // Print dummy_string from JRuby code try { jrEngine.eval("puts(javaobject)") ; }catch (ScriptException exception) { exception.printStackTrace() ; }
  • 46. Ruby Ruby on Rails Demo Summary JRuby JRuby Why JRuby ? JRuby over Ruby Compilation Better performance and scalability than Ruby (eg : native threading) Native unicode support Java API + java libraries JRuby over Java Ruby language : dynamic typing, blocks, modules, metoprogramming Ruby applications : Ruby on Rails, Rake, Raven etc
  • 47. Ruby Ruby on Rails Demo Summary JRuby JRuby Why JRuby ? JRuby over Ruby Compilation Better performance and scalability than Ruby (eg : native threading) Native unicode support Java API + java libraries JRuby over Java Ruby language : dynamic typing, blocks, modules, metoprogramming Ruby applications : Ruby on Rails, Rake, Raven etc
  • 48. Ruby Ruby on Rails Demo Summary JRuby JRuby on Rails Jruby on Rails Part of JRuby project Brings power and functionality of Java to Ruby on Rails : Call scripts, script functions, methods and objects from Java Deployment of ROR apps to JEE application servers (switch framework VS switch whole architecture) Java scalability (eg : database pooling) Java libraries Integration with java legacy apps
  • 49. Ruby Ruby on Rails Demo Summary JRuby JRuby on Rails Jruby on Rails Part of JRuby project Brings power and functionality of Java to Ruby on Rails : Call scripts, script functions, methods and objects from Java Deployment of ROR apps to JEE application servers (switch framework VS switch whole architecture) Java scalability (eg : database pooling) Java libraries Integration with java legacy apps
  • 50. Ruby Ruby on Rails Demo Summary JRuby Future of JRuby JRuby Future ? RoR lack of maturity JRuby : bring power of JVMs, JEE application servers and libraries to RoR => lower barrier of entry Glassfish V3 (Sun JEE application server) will allows to run other containers than JEE : RoR, PHP etc
  • 51. Ruby Ruby on Rails Demo Summary JRuby Future of JRuby Q&A Thank you
  • 52. Ruby Ruby on Rails Demo Summary JRuby Future of JRuby Ruby on Rails Tristan Bigourdan David Alphen Sales & e-Commerce Platform Server Architecture & Frameworks Internship 2007
  • 53. Appendix Bibliographie More Information I Dave Thomas Programming Ruby 2nd edition. Pragmatic Programmers 2005. David Heinemeier Hansson Agile Web Development with Rails 2nd edition. Pragmatic Programmers 2007. Memo http ://www.zenspider.com/Languages/Ruby/QuickRef.html Good memo. Ruby Doc http ://www.ruby-doc.org Standard and Core Librairies APIs.
  • 54. Appendix Bibliographie More Information II Ruby Garden http ://www.rubygarden.org Ruby tutorials, wiki, . . . Ruby On Rails http ://www.rubyonrails.org RoR doc, tutorials, wiki, . . . JRuby http ://www.jruby.org JRuby doc, tutorials, wiki, . . .