- Published: 10 May 2011
In this tutorial we will show how to develop a Ruby on Rails application on JBoss AS using TorqueBox project in just 10 steps!
Before diving into this tutorial we would need some basic definitions:
Surely some of you have hear about Ruby programming language which is an object oriented dynamic language very popular among Linux users.
Ruby on Rails is a MVC framework developed in Ruby for delivering quickly web applications.
JRuby is a fast, compliant implementation of the Ruby language upon the Java Virtual Machine. Pure Ruby applications run un-modified within the JRuby interpreter.
All these three components, combine into Torquebox which provides an all-in-one environment to run Ruby / RubyonRails applications on the top of JBoss AS
Step 1: Installing Torquebox
Prerequisite: you need a JDK 1.6 in order to run Torquebox
Download Torquebox from here and extract in a folder.
Step 2: Set up some system environment variables
Supposing you installed Torquebox into C:\torquebox-1.0.0
Then add to your PATH environment variable jruby bin commands:
Step 3: Install rails libraries
Ruby libraries are distributed as gem packages. A gem libraries contains the package information along with files to install.
So we will use the “gem” shell command to install the basic rails libraries:
C:\torquebox-1.0.0>gem install rails
Fetching: activesupport-3.0.7.gem (100%)
Fetching: builder-2.1.2.gem (100%)
Fetching: i18n-0.5.0.gem (100%)
Fetching: activemodel-3.0.7.gem (100%)
Fetching: rack-1.2.2.gem (100%)
Fetching: rack-test-0.5.7.gem (100%)
23 gems installed
Installation hack: If you are running behind a proxy you should use:
gem install -p http://<proxy-url> rails
Windows users should use the HTTP_PROXY environment variable
Step 4: Install Rake support
TorqueBox includes a support package which includes Rake tasks which assist in the deployment to and undeployment from an instance of the TorqueBox Server. Install it using gem utility:
C:\torquebox-1.0.0>gem install torquebox-rake-support
Fetching: torquebox-rake-support-1.0.0.gem (100%)
Successfully installed torquebox-rake-support-1.0.0
1 gem installed
Step 5: Create a new Rails application
Applications can be created using the rails utility which provides a skeleton for a basic MVC application. With the following code we will create a new web application named "example"
C:\torquebox-1.0.0\rails new example
Step 6: Install a JDBC adapter for your application
There are several ways to connect a RubyOnRails application to a database. You can install native adapters for databases like MySQL, Postgres. However for Java users, the simplest approach is installing JDBC adapters which enables your Ruby on Rails application to access database servers that provide JDBC 3.0 compliant drivers.
For our purpose we will use a mysql JDBC adapter
C:\torquebox-1.0.0>gem install activerecord-jdbcmysql-adapter
Fetching: jdbc-mysql-5.1.13.gem (100%)
Fetching: activerecord-jdbcmysql-adapter-1.1.1.gem (100%)
Successfully installed jdbc-mysql-5.1.13
Successfully installed activerecord-jdbcmysql-adapter-1.1.1
2 gems installed
Step 7: Customize your application
Move into the “example” folder and open the Rakefile file which contains the Rake configuration.
Add the following line:
In the same folder, open the Gemfile file and add the following:
Finally open the config/database.yml file which contains the database configuration.
Here we configure RubyonRails to connect to a MySQL instance running on the same host
Now Let's move to MySQL shell and create an empty database named rubyonrails:
mysql> create database rubyonrails;
Query OK, 1 row affected (0.00 sec)
- Next >>