Joshua Java

Posts Tagged ‘rails

2009 is coming to your way and it’s time to get ready on what technology lies ahead. Refactor, refactor and refactor is the theme for 2009. A whole new technology is coming your way and it’s good to take a sneak peek on what technology is worth evaluating to be used for our projects in 2009. The first half technology are the technologies that you should keep your eyes at while the next half are the technologies that you might want to start trying for your next project in 2009. So here are the lists for 2009:
Read the rest of this entry »

Advertisements

I’ve been wanting to write tutorial on JRuby on Rails for my personal reference but couldn’t really find the time for it. Now here’s a short tutorial on JRuby on Rails that hopefully be useful for you.

Download the required prerequisites:
JDK: http://java.sun.com
JRuby: http://dist.codehaus.org/jruby/

Set proxy if you are behind a proxy by setting to environment variable http_proxy.

Set up your environment variables so you can access the jruby command straight from the console. First set the JRUBY_HOME enviroment variable, then add another entry for PATH variable: $JRUBY_HOME/bin.

Update the gems required for the rails project:
jruby -S jgem install rails mongrel rake ActiveRecord-JDBC activerecord-jdbc-adapter

Put in the jdbc driver inside: $JRUBY_HOME/lib
For this tutorial I use mysql-jdbc driver.

Create rails project by executing this command from the console:
jruby -S rails jugreg

Start the webserver by executing this command from the command line:
mongrel_rails start -e development

Now you can view your generated project from the browser by pointing to this URL:
http://localhost:3000

If you can see this screenshot from your browser then you’ve succeed creating Rails project with JRuby. As you can see, the environment is using JRuby implementation and JDBC for the database adapter.

Go inside to the rails project folder namely jugreg and open config/database.yml from there, edit it as such according to your database environment:
development:
adapter: jdbc
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/jugreg
username: joshua
password: password

Now you create the jugreg database. With mysql this is what I would do from mysql command line:
create database jugreg;

Now we’re going to generate all the source for Member with this command from the project folder:
jruby script/generate scaffold Member name:string position:string incumbency:string company:string website:string phone:string email:string javaprog:boolean usejava:boolean experience:integer

Then execute this command so rake will generate the member table on the database
jruby -S rake db:create:all
jruby -S rake db:migrate

Start the webserver by executing this command from the command line:
mongrel_rails start -e production
The “-e” flag indicates the environment you want to use. By default there are 3 enviroment as you can see from the config/environments

Now you can view member list page from the browser by pointing to this URL:
http://localhost:3000/members

If you want to see the entry form page from the browser, you can point on your browser to this URL:
http://localhost:3000/members/new

That’s all for now. Hopefully it will be useful for you. If you find any difficulties please don’t hesitate to contact me.

Tags: ,