O'Reilly logo

JRuby Cookbook by Justin Edelson, Henry Liu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. JRuby on Rails

Introduction

Since its introduction in mid-2004, the Ruby on Rails web framework has rapidly gained a significant following within the web development community. It is the single largest factor in the overall increase in interest in the Ruby programming language. Likewise, JRuby’s ability to run Rails applications inside a Java Virtual Machine has been a driver for interest in JRuby. This chapter explores some techniques for running Rails applications in a Java environment.

Ruby on Rails is a framework for developing web applications that follows the model-view-controller (MVC) architecture. The notion of Convention over Configuration is stressed throughout the framework, most prevalently within ActiveRecord, the object-relational-mapping (ORM) subsystem. ActiveRecord uses database metadata (table and column names) to dynamically define domain classes. Using ActiveRecord, simply adding a new column to a database table automatically adds a corresponding field to the related domain class.

Running Rails applications on JRuby provides several advantages:

  • Rails applications can be deployed into existing Java EE containers such as Tomcat, JBoss, and GlassFish.

  • Through Java Database Connectivity (JDBC), Rails applications can be connected to virtually any database for which a JDBC driver exists.

  • Rails applications can access container-managed database connection pools through Java Naming and Directory Interface (JNDI).

In short, the combination of JRuby and Rails produces ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required