SlideShare a Scribd company logo
Rapid Web
Application
Development using
Ruby on Rails
●
 Sang Shin
●Sun Microsystems, Inc.

●
 javapassion.com

                          1
You can try all the demos
yourself!

Join “Ruby, JRuby, Rails”
free online course!

www.javapassion.com/rubyonrails
Topics
•   What is and Why Ruby on Rails (Rails)?
•   Rails Basics
•   Step by step for building “Hello World” Rails application
•   ActiveRecord
•   ActionController
•   ActionView
•   Deployment




                                                                3
What is and Why
Ruby on Rails (RoR)?
What Is “Ruby on Rails”?
• A full-stack MVC web development framework
• Written in Ruby
• First released in 2004 by
  David Heinemeier Hansson
• Gaining popularity




                                               5
“Ruby on Rails” Principles
• Convention over configuration
  > Why punish the common cases?
  > Encourages standard practices
  > Everything simpler and smaller
• Don’t Repeat Yourself (DRY)
  > Repetitive code is harmful to adaptability
• Agile development environment
  > No recompile, deploy, restart cycles
  > Simple tools to generate code quickly
  > Testing built into the framework
                                                 6
Rails Basics
“Ruby on Rails” MVC




                      source: http://www.ilug-cal.org   8
Step By Step Process
of Building “Hello World”
Rails Application
Steps to Follow
1.Create “Ruby on Rails” project
  > IDE generate necessary directories and files
2.Create and populate database tables
3.Create Models (through Rails Generator)
  > Migrate database
4.Create Controllers (through Rails Generator)
5.Create Views
6.Set URL Routing
  > Map URL to controller and action
                                                   10
Demo:
    Building “Hello World”
Rails Application Step by Step.

 http://www.javapassion.com/handsonlabs/rails_basics/#Exercise_1




                                                                   11
Key Learning Points
• How to create a Rails project
    > Rails application directory structure
    > Concept of environments - development, test, and
      production
•   How to create a database using Rake
•   How to create and populate tables using Migration
•   How to create a model using Generator
•   How to use Rails console

                                                         12
Key Learning Points
• How to create a controller using Generator
  > How to add actions to a controller
• How to create a related view
  > How a controller and a view are related
  > How to create instance variables in an action and they
    are used in a view
• How to set up a routing
• How to trouble-shoot a problem

                                                             13
Demo:
How to create an input form.

http://www.javapassion.com/handsonlabs/rails_basics/#Exercise_4




                                                                  14
Key Learning Points
• How to use form_tag and text_field helpers to
  create an input form
• How input form fields are accessed in an action
  method through params




                                                    15
Scaffolding
What is Scaffolding?
• Scaffolding is a way to quickly create a CRUD
  application
  > Rails framework generates a set of actions for listing,
    showing, creating, updating, and destroying objects of
    the class
  > These standardized actions come with both controller
    logic and default templates that through introspection
    already know which fields to display and which input
    types to use
• Supports RESTful view of the a Model
                                                              17
Demo:
Creating a Rails Application
     using Scaffolding

http://www.javapassion.com/handsonlabs/rails_scaffold/#Exercise_1




                                                                    18
Key Learning Points
• How to perform scaffolding using Generator
• What action methods are created through
  scaffolding
• What templates are created through scaffolding




                                                   19
ActiveRecord
Basics
ActiveRecord Basics
• Model (from MVC)
• Object Relation Mapping library
  > A table maps to a Ruby class (Model)
  > A row maps to a Ruby object
  > Columns map to attributes
• Database agnostic
• Your model class extends ActiveRecord::Base


                                                21
ActiveRecord Class
• Your model class extends ActiveRecord::Base
  class User < ActiveRecord::Base
  end
• You model class contain domain logic
  class User < ActiveRecord::Base
     def self.authenticate_safely(user_name, password)
      find(:first, :conditions => [ "user_name = ? AND
     password = ?", user_name, password ])
     end
  end                                                    22
Naming Conventions
• Table names are plural and class names are
  singular
  > posts (table), Post (class)
  > students (table), Student (class)
  > people (table), Person (class)
• Tables contain a column named id




                                               23
Find: Examples
• find by id
  Person.find(1)     # returns the object for ID = 1
  Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6)
• find first
  Person.find(:first) # returns the first object fetched by SELECT * FROM peop
  Person.find(:first, :conditions => [ "user_name = ?", user_name])
  Person.find(:first, :order => "created_on DESC", :offset => 5)




                                                                              24
Dynamic attribute-based finders
• Dynamic attribute-based finders are a cleaner way
  of getting (and/or creating) objects by simple
  queries without turning to SQL
• They work by appending the name of an attribute to
  find_by_ or find_all_by_, so you get finders like
  > Person.find_by_user_name(user_name)
     > Person.find(:first, :conditions => ["user_name = ?",
       user_name])
  > Person.find_all_by_last_name(last_name)
     > Person.find(:all, :conditions => ["last_name = ?", last_name])
  > Payment.find_by_transaction_id
                                                                        25
ActiveRecord
Migration
ActiveRecord Migration
• Provides version control of database schema
  > Adding a new field to a table
  > Removing a field from an existing table
  > Changing the name of the column
  > Creating a new table
• Each change in schema is represented in pure
  Ruby code



                                                 27
Example: Migration
• Add a boolean flag to the accounts table and remove it
  again, if you’re backing out of the migration.

  class AddSsl < ActiveRecord::Migration
     def self.up
      add_column :accounts, :ssl_enabled, :boolean, :default => 1
     end

    def self.down
     remove_column :accounts, :ssl_enabled
    end
   end                                                       28
Demo:
How to add a field to a table
     using Migration

http://www.javapassion.com/handsonlabs/rails_scaffold/#Exercise_2




                                                                    29
Key Learning Points
• How to add a new field to a table using Migration
• How to create a migration file using Generator
• How to see a log file




                                                      30
ActiveRecord
Validation
ActiveRecord::Validations
• Validation methods
  class User < ActiveRecord::Base
   validates_presence_of :username, :level
   validates_uniqueness_of :username
   validates_oak_id :username
   validates_length_of :username, :maximum => 3, :allow_nil
   validates_numericality_of :value, :on => :create
  end


                                                          32
Validation




             33
Demo:
                 Validation
http://www.javapassion.com/handsonlabs/rails_scaffold/#2.4




                                                             34
ActiveRecord::
Associations
Associations
• Associations are a set of macro-like class methods
  for tying objects together through foreign keys.
• They express relationships like "Project has one
  Project Manager" or "Project belongs to a Portfolio".
• Each macro adds a number of methods to the class
  which are specialized according to the collection or
  association symbol and the options hash.
• Cardinality
  > One-to-one, One-to-many, Many-to-many
                                                          36
One-to-many
• Use has_many in the base, and belongs_to in the
  associated model

   class Manager < ActiveRecord::Base
    has_many :employees
   end
   class Employee < ActiveRecord::Base
    belongs_to :manager # foreign key - manager_id
   end
                                                     37
Demo:
               Association
http://www.javapassion.com/handsonlabs/rails_activerecord/




                                                             38
ActionController
Basics
ActionController
• Controller is made up of one or more actions that are
  executed on request and then either render a template or
  redirect to another action
• An action is defined as a public method on the controller,
  which will automatically be made accessible to the web-
  server through Rails Routes
• Actions, by default, render a template in the app/views
  directory corresponding to the name of the controller and
  action after executing code in the action.


                                                               40
ActionController
• For example, the index action of the GuestBookController would
  render the template app/views/guestbook/index.erb by default
  after populating the @entries instance variable.

  class GuestBookController < ActionController::Base
     def index
      @entries = Entry.find(:all)
     end

    def sign
     Entry.create(params[:entry])
     redirect_to :action => "index"
    end
   end
                                                               41
Deployment
Web Servers
• By default, Rails will try to use Mongrel and lighttpd
  if they are installed, otherwise Rails will use
  WEBrick, the webserver that ships with Ruby.
• Java Server integration
  > Goldspike
  > GlassFish V3




                                                           43
Goldspike
• Rails Plugin
• Packages Rails application as WAR
• WAR contains a servlet that translates data from the
  servlet request to the Rails dispatcher
• Works for any servlet container
• rake war:standalone:create



                                                     44
Demo:
        Deployment through
            Goldspike

http://www.javapassion.com/handsonlabs/rails_deploy/#Exercise_1




                                                                  45
JRuby on Rails
Why “JRuby on Rails”
over “Ruby on Rails”?
• Java technology production environments pervasive
  > Easier to switch framework vs. whole architecture
  > Lower barrier to entry
• Integration with Java technology libraries,
  legacy services
• No need to leave Java technology servers, libraries,
  reliability
• Deployment to Java application servers
                                                         47
“JRuby on Rails”: Java EE Platform
• Pool database connections
• Access any Java Naming and Directory Interface™
  (J.N.D.I.) API resource
• Access any Java EE platform TLA:
  > Java Persistence API (JPA)
  > Java Management Extensions (JMX™)
  > Enterprise JavaBeans™ (EJB™)
  > Java Message Service (JMS) API
  > SOAP/WSDL/SOA
                                                    48
Rapid Web
Application
Development using
Ruby on Rails
●
 Sang Shin
●Sun Microsystems, Inc.

●
 javapassion.com

                          49

More Related Content

PDF
RicoLiveGrid
PPT
JavaScript
PDF
Drupal & javascript
DOC
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
PDF
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
PDF
Single page webapps & javascript-testing
PPTX
IndexedDB - Querying and Performance
PDF
Rails Best Practices
RicoLiveGrid
JavaScript
Drupal & javascript
No Coding Necessary: Building Confluence User Macros Cheat Sheet - Atlassian ...
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluen...
Single page webapps & javascript-testing
IndexedDB - Querying and Performance
Rails Best Practices

What's hot (19)

PDF
Advanced Django
PDF
Ajax nested form and ajax upload in rails
PPT
jQuery and_drupal
PDF
Demystifying Drupal AJAX Callback Commands
PDF
Building Web Interface On Rails
PDF
Alfredo-PUMEX
PDF
Demystifying AJAX Callback Commands in Drupal 8
PPTX
Making Magento flying like a rocket! (A set of valuable tips for developers)
PPT
Drupal Javascript for developers
PDF
Apache Con Us2007 Apachei Batis
 
PDF
MidCamp 2016 - Demystifying AJAX Callback Commands in Drupal 8
PDF
Introduction to backbone presentation
PDF
Class-based views with Django
PDF
PDF
TurboGears2 Pluggable Applications
PDF
Drupal 8 Services
PDF
Drupal8Day: Demystifying Drupal 8 Ajax Callback commands
PDF
Михаил Крайнюк - Form API + Drupal 8: Form and AJAX
Advanced Django
Ajax nested form and ajax upload in rails
jQuery and_drupal
Demystifying Drupal AJAX Callback Commands
Building Web Interface On Rails
Alfredo-PUMEX
Demystifying AJAX Callback Commands in Drupal 8
Making Magento flying like a rocket! (A set of valuable tips for developers)
Drupal Javascript for developers
Apache Con Us2007 Apachei Batis
 
MidCamp 2016 - Demystifying AJAX Callback Commands in Drupal 8
Introduction to backbone presentation
Class-based views with Django
TurboGears2 Pluggable Applications
Drupal 8 Services
Drupal8Day: Demystifying Drupal 8 Ajax Callback commands
Михаил Крайнюк - Form API + Drupal 8: Form and AJAX
Ad

Viewers also liked (7)

PDF
PDF
fms9_cwp_php_en
PDF
INFS730
PPS
FW: ARTE C ON LÀPICES
DOCX
Problemas act 2.1
PDF
Alfredo-PUMEX
fms9_cwp_php_en
INFS730
FW: ARTE C ON LÀPICES
Problemas act 2.1
Alfredo-PUMEX
Ad

Similar to td_mxc_rubyrails_shin (20)

PPT
Ruby on Rails: Building Web Applications Is Fun Again!
PPTX
12 Introduction to Rails
PDF
Introduction to Ruby on Rails
PDF
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
PDF
Ruby On Rails
KEY
Supa fast Ruby + Rails
PDF
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
PPT
Ruby On Rails
KEY
Desarrollando aplicaciones web en minutos
DOC
Rails interview questions
PDF
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
PDF
Connecting the Worlds of Java and Ruby with JRuby
PPT
Ruby on rails
PDF
Rails - getting started
KEY
Rails Model Basics
PPT
Introduction To Ruby On Rails
PPTX
Learning to code for startup mvp session 3
PDF
Lecture #5 Introduction to rails
PDF
Introduction to Rails by Evgeniy Hinyuk
PPT
Ruby On Rails Siddhesh
Ruby on Rails: Building Web Applications Is Fun Again!
12 Introduction to Rails
Introduction to Ruby on Rails
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby On Rails
Supa fast Ruby + Rails
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby On Rails
Desarrollando aplicaciones web en minutos
Rails interview questions
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Connecting the Worlds of Java and Ruby with JRuby
Ruby on rails
Rails - getting started
Rails Model Basics
Introduction To Ruby On Rails
Learning to code for startup mvp session 3
Lecture #5 Introduction to rails
Introduction to Rails by Evgeniy Hinyuk
Ruby On Rails Siddhesh

More from tutorialsruby (20)

PDF
&lt;img src="../i/r_14.png" />
PDF
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
PDF
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
PDF
&lt;img src="../i/r_14.png" />
PDF
&lt;img src="../i/r_14.png" />
PDF
Standardization and Knowledge Transfer – INS0
PDF
xhtml_basics
PDF
xhtml_basics
PDF
xhtml-documentation
PDF
xhtml-documentation
PDF
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
PDF
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
PDF
HowTo_CSS
PDF
HowTo_CSS
PDF
BloggingWithStyle_2008
PDF
BloggingWithStyle_2008
PDF
cascadingstylesheets
PDF
cascadingstylesheets
&lt;img src="../i/r_14.png" />
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
Standardization and Knowledge Transfer – INS0
xhtml_basics
xhtml_basics
xhtml-documentation
xhtml-documentation
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
HowTo_CSS
HowTo_CSS
BloggingWithStyle_2008
BloggingWithStyle_2008
cascadingstylesheets
cascadingstylesheets

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Approach and Philosophy of On baking technology
PDF
KodekX | Application Modernization Development
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Machine learning based COVID-19 study performance prediction
PPTX
A Presentation on Artificial Intelligence
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
NewMind AI Weekly Chronicles - August'25 Week I
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Approach and Philosophy of On baking technology
KodekX | Application Modernization Development
Dropbox Q2 2025 Financial Results & Investor Presentation
Machine learning based COVID-19 study performance prediction
A Presentation on Artificial Intelligence
The AUB Centre for AI in Media Proposal.docx
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...

td_mxc_rubyrails_shin

  • 1. Rapid Web Application Development using Ruby on Rails ● Sang Shin ●Sun Microsystems, Inc. ● javapassion.com 1
  • 2. You can try all the demos yourself! Join “Ruby, JRuby, Rails” free online course! www.javapassion.com/rubyonrails
  • 3. Topics • What is and Why Ruby on Rails (Rails)? • Rails Basics • Step by step for building “Hello World” Rails application • ActiveRecord • ActionController • ActionView • Deployment 3
  • 4. What is and Why Ruby on Rails (RoR)?
  • 5. What Is “Ruby on Rails”? • A full-stack MVC web development framework • Written in Ruby • First released in 2004 by David Heinemeier Hansson • Gaining popularity 5
  • 6. “Ruby on Rails” Principles • Convention over configuration > Why punish the common cases? > Encourages standard practices > Everything simpler and smaller • Don’t Repeat Yourself (DRY) > Repetitive code is harmful to adaptability • Agile development environment > No recompile, deploy, restart cycles > Simple tools to generate code quickly > Testing built into the framework 6
  • 8. “Ruby on Rails” MVC source: http://www.ilug-cal.org 8
  • 9. Step By Step Process of Building “Hello World” Rails Application
  • 10. Steps to Follow 1.Create “Ruby on Rails” project > IDE generate necessary directories and files 2.Create and populate database tables 3.Create Models (through Rails Generator) > Migrate database 4.Create Controllers (through Rails Generator) 5.Create Views 6.Set URL Routing > Map URL to controller and action 10
  • 11. Demo: Building “Hello World” Rails Application Step by Step. http://www.javapassion.com/handsonlabs/rails_basics/#Exercise_1 11
  • 12. Key Learning Points • How to create a Rails project > Rails application directory structure > Concept of environments - development, test, and production • How to create a database using Rake • How to create and populate tables using Migration • How to create a model using Generator • How to use Rails console 12
  • 13. Key Learning Points • How to create a controller using Generator > How to add actions to a controller • How to create a related view > How a controller and a view are related > How to create instance variables in an action and they are used in a view • How to set up a routing • How to trouble-shoot a problem 13
  • 14. Demo: How to create an input form. http://www.javapassion.com/handsonlabs/rails_basics/#Exercise_4 14
  • 15. Key Learning Points • How to use form_tag and text_field helpers to create an input form • How input form fields are accessed in an action method through params 15
  • 17. What is Scaffolding? • Scaffolding is a way to quickly create a CRUD application > Rails framework generates a set of actions for listing, showing, creating, updating, and destroying objects of the class > These standardized actions come with both controller logic and default templates that through introspection already know which fields to display and which input types to use • Supports RESTful view of the a Model 17
  • 18. Demo: Creating a Rails Application using Scaffolding http://www.javapassion.com/handsonlabs/rails_scaffold/#Exercise_1 18
  • 19. Key Learning Points • How to perform scaffolding using Generator • What action methods are created through scaffolding • What templates are created through scaffolding 19
  • 21. ActiveRecord Basics • Model (from MVC) • Object Relation Mapping library > A table maps to a Ruby class (Model) > A row maps to a Ruby object > Columns map to attributes • Database agnostic • Your model class extends ActiveRecord::Base 21
  • 22. ActiveRecord Class • Your model class extends ActiveRecord::Base class User < ActiveRecord::Base end • You model class contain domain logic class User < ActiveRecord::Base def self.authenticate_safely(user_name, password) find(:first, :conditions => [ "user_name = ? AND password = ?", user_name, password ]) end end 22
  • 23. Naming Conventions • Table names are plural and class names are singular > posts (table), Post (class) > students (table), Student (class) > people (table), Person (class) • Tables contain a column named id 23
  • 24. Find: Examples • find by id Person.find(1) # returns the object for ID = 1 Person.find(1, 2, 6) # returns an array for objects with IDs in (1, 2, 6) • find first Person.find(:first) # returns the first object fetched by SELECT * FROM peop Person.find(:first, :conditions => [ "user_name = ?", user_name]) Person.find(:first, :order => "created_on DESC", :offset => 5) 24
  • 25. Dynamic attribute-based finders • Dynamic attribute-based finders are a cleaner way of getting (and/or creating) objects by simple queries without turning to SQL • They work by appending the name of an attribute to find_by_ or find_all_by_, so you get finders like > Person.find_by_user_name(user_name) > Person.find(:first, :conditions => ["user_name = ?", user_name]) > Person.find_all_by_last_name(last_name) > Person.find(:all, :conditions => ["last_name = ?", last_name]) > Payment.find_by_transaction_id 25
  • 27. ActiveRecord Migration • Provides version control of database schema > Adding a new field to a table > Removing a field from an existing table > Changing the name of the column > Creating a new table • Each change in schema is represented in pure Ruby code 27
  • 28. Example: Migration • Add a boolean flag to the accounts table and remove it again, if you’re backing out of the migration. class AddSsl < ActiveRecord::Migration def self.up add_column :accounts, :ssl_enabled, :boolean, :default => 1 end def self.down remove_column :accounts, :ssl_enabled end end 28
  • 29. Demo: How to add a field to a table using Migration http://www.javapassion.com/handsonlabs/rails_scaffold/#Exercise_2 29
  • 30. Key Learning Points • How to add a new field to a table using Migration • How to create a migration file using Generator • How to see a log file 30
  • 32. ActiveRecord::Validations • Validation methods class User < ActiveRecord::Base validates_presence_of :username, :level validates_uniqueness_of :username validates_oak_id :username validates_length_of :username, :maximum => 3, :allow_nil validates_numericality_of :value, :on => :create end 32
  • 34. Demo: Validation http://www.javapassion.com/handsonlabs/rails_scaffold/#2.4 34
  • 36. Associations • Associations are a set of macro-like class methods for tying objects together through foreign keys. • They express relationships like "Project has one Project Manager" or "Project belongs to a Portfolio". • Each macro adds a number of methods to the class which are specialized according to the collection or association symbol and the options hash. • Cardinality > One-to-one, One-to-many, Many-to-many 36
  • 37. One-to-many • Use has_many in the base, and belongs_to in the associated model class Manager < ActiveRecord::Base has_many :employees end class Employee < ActiveRecord::Base belongs_to :manager # foreign key - manager_id end 37
  • 38. Demo: Association http://www.javapassion.com/handsonlabs/rails_activerecord/ 38
  • 40. ActionController • Controller is made up of one or more actions that are executed on request and then either render a template or redirect to another action • An action is defined as a public method on the controller, which will automatically be made accessible to the web- server through Rails Routes • Actions, by default, render a template in the app/views directory corresponding to the name of the controller and action after executing code in the action. 40
  • 41. ActionController • For example, the index action of the GuestBookController would render the template app/views/guestbook/index.erb by default after populating the @entries instance variable. class GuestBookController < ActionController::Base def index @entries = Entry.find(:all) end def sign Entry.create(params[:entry]) redirect_to :action => "index" end end 41
  • 43. Web Servers • By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise Rails will use WEBrick, the webserver that ships with Ruby. • Java Server integration > Goldspike > GlassFish V3 43
  • 44. Goldspike • Rails Plugin • Packages Rails application as WAR • WAR contains a servlet that translates data from the servlet request to the Rails dispatcher • Works for any servlet container • rake war:standalone:create 44
  • 45. Demo: Deployment through Goldspike http://www.javapassion.com/handsonlabs/rails_deploy/#Exercise_1 45
  • 47. Why “JRuby on Rails” over “Ruby on Rails”? • Java technology production environments pervasive > Easier to switch framework vs. whole architecture > Lower barrier to entry • Integration with Java technology libraries, legacy services • No need to leave Java technology servers, libraries, reliability • Deployment to Java application servers 47
  • 48. “JRuby on Rails”: Java EE Platform • Pool database connections • Access any Java Naming and Directory Interface™ (J.N.D.I.) API resource • Access any Java EE platform TLA: > Java Persistence API (JPA) > Java Management Extensions (JMX™) > Enterprise JavaBeans™ (EJB™) > Java Message Service (JMS) API > SOAP/WSDL/SOA 48
  • 49. Rapid Web Application Development using Ruby on Rails ● Sang Shin ●Sun Microsystems, Inc. ● javapassion.com 49