The GlassFish application server provides excellent deployment solutions for JRuby on Rails applications. From this guide you can learn how to create a simple Rails application using JRuby and deploy it on the GlassFish application server. Installing JRuby and Rails To get started creating JRuby on Rails applications, you need to install JRuby and Rails by performing the following steps. Be sure to use the latest versions of JRuby and Rails so that you benefit from the newest features and bug fixes.
- Install JRuby by following the instructions in the JRuby Getting Started Guide.
- Install Rails on your JRuby installation by following the instructions in Rails setup on JRuby.
Creating a Hello World Application Create a template application by running the following command:
Create a controller and view by performing the following steps: 1. Go to the hello directory:
2. Enter the following command to generate a controller and default view for the hello application:
jruby script/generate controller say hello
Create a variable in the controller by doing the following: 1. Open the controller, say_controller.rb, in a text editor, such as vi:
vi app/controllers/say_controller.rb
2. Add the following string to the controller's hello helper method:
@hello_string = "v3 Gem is getting polished!"
Retrieve the value of @hello_string in the view by doing the following: 1. Open the view in a text editor:
- For Rails 2.1.0, open hello.html.erb in a text editor, such as vi:
vi app/views/say/hello.html.erb
- For Rails 1.2.6, open app/views/say/hello.rhtml in a text editor, such as vi:
vi app/views/say/hello.rhtml
2. Add the following string at the bottom of the view:
Configure a Database if Using Rails 2.1.0 Perform the steps in this section only if you are using Rails 2.1.0. If you are running earlier versions of Rails, such as version 1.2.6, skip this section. In the hello sample, you do not need a database, so you should do one of the following two things:
- Configure Rails to disable the database:
- Open the hello/config/environment.rb file in a text editor.
- Remove the hash mark (#) from the beginning of line 21 so that it looks like this:
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
Even though you don't have a model in the hello sample, Rails 2.1.0 expects you to create a database, which you do by running the following command after you have created the scaffold:
This command creates the database, hello_development. Deploy and run Rails on GlassFish gem The fastest and easiest way to deploy and run your Rails applications is to do so on the GlassFish gem. The GlassFish gem consists of only the GlassFish v3 kernel, Grizzly, and some utilities, thereby resulting in a smaller size a and faster startup time. You only need perform a one-time installation of the GlassFish gem to deploy and run applications on it. Deploy and run Rails on GlassFish v3 While the GlassFish gem offers a robust and easy-to-use deployment environment, sometimes you need to use Java<sup>TM</sup> EE features from inside your Rails application and for this you need to deploy the application to the GlassFish v3 server. Deploy and run Rails on Glassfish v2 You can deploy a Rails application on the GlassFish v2 application server by packaging it as a web archive (WAR) file. You perform this packaging using Goldspike, which is available with the JRuby on Rails GlassFish v2 UC module.
|