Rails 3.1 and JRuby

Posted by arunagw on October 10, 2011

Hi Folks,

If you are doing any application in which you required JRuby as a platform. You can use Rails3.1 with that. activerecord-jdbc-adapter 1.2.0 is ok with that!

All the steps are same as for the normal Rails Application

You can find more details here http://blog.jruby.org/2011/09/ar-jdbc-1-2-0-released/

 

Cheers,
Arun

Rails 3.0.10 and JRuby 1

Posted by arunagw on August 05, 2011

Finally, The Rails is coming with template support with JRuby platform. We used to use “-m” option to generate new Rails Application for JRuby platform. Which is no more need now.

Just set your platform to JRuby and create a new Rails Application as you do normally and it will generate a Application which is ready to go. No more tweaks required..!!

This pull request which get merged into Rails 3-0-stable branch and it’s shipped with Rails 3.0.10.rc1 and will come with Rails 3.0.10.

This feature is also coming with Rails 3.1.

Showing here some of the example which will create Rails Application for JRuby platform. I have tested this on JRuby 1.6.3 version.

rvm jruby-1.6.3
# Will set your environment for JRuby 1.6.3 version.

Time to create rails app. This will generate a rails app for JRuby platform. Things like database.yml, Gemfile will generated specifically for JRuby platform.

rails new myapp

database.yml

# SQLite version 3.x
#   gem 'activerecord-jdbcsqlite3-adapter'

development:
  adapter: sqlite3
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3

production:
  adapter: sqlite3
  database: db/production.sqlite3

Gemfile

source 'http://rubygems.org'

gem 'rails', '3.0.10.rc1'

gem 'jruby-openssl'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'activerecord-jdbcsqlite3-adapter'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
#   gem 'webrat'
# end

You can see in Gemfile the changes. It requires gem 'jruby-openssl' gem and gem 'activerecord-jdbcsqlite3-adapter' gem. Which is required for JRuby platform.

Same work to generate for mysql and postgres.

rails new myapp -d mysql

And that’s all.!!

Your Application is ready to run. Just do bundle install and all set. wOOtt..!!

Post comments and discuss things if you guys still facing any issue. You can also post issue on Rails Issues and ask me to look into that.

Some Useful links related to post:

  1. Activerecord-jdbc-adapter
  2. Jruby.org
Cheers,

Rails3 application with Jruby 1

Posted by arunagw on March 28, 2011

If you are living on edge and you are using Rails3 then you need follow this. Rails3 With JRuby

 

Hi All,

Recently i have started a Rails3 application which will use Jruby.

I have gone through some of the steps for that application up and running.

If you are using RVM then it’s easy to install Jruby. In the latest RVM version Jruby-1.6.0 is the default one. So my recommendation is first update the RVM itself then install Jruby.

To update RVM and get the Jruby-1.6.0 installed

rvm update 
# But if you are already on the latest RVM then you will get message the "rvm update has been removed".

#To install Jruby

rvm install jruby

After installing Jruby you need to switch your environment to Jruby

 
rvm use jruby
#Using /Users/arunagw/.rvm/gems/jruby-1.6.0

Can check by using

~~>jruby -v                                                                                                                                                                          
jruby 1.6.0 (ruby 1.8.7 patchlevel 330) (2011-03-15 f3b6154) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_22) [darwin-x86_64-java]
~~>ruby -v                                                                                                                                                                           
jruby 1.6.0 (ruby 1.8.7 patchlevel 330) (2011-03-15 f3b6154) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_22) [darwin-x86_64-java]

Now you are ready to play with Jruby stuff.

You can do some basic stuff like irb to test things

irb
#IRB will also work
jirb
# JIRB will also work

Time to install Rails in Jruby environment

gem install rails 

#Will also work

jruby -S gem install rails

All set. Create your Rails application.

rails new my_app

Above command will create a rails application but not useful for Jruby platform.

For all setting just run

rails new my_app -m http://jruby.org/rails3.rb

This will do all setup for you for a rails3 app in Jruby.

You may need to change/update your Gemfile for your gems.

Problems i faced.

rake db:create will give you an error if you are using Mysql with Jruby.

uninitialized constant Mysql::Error

Here is the ticket information about this.

Solution for this problem right now is to create database manually.

After that all will work. No more hurdles i found.

If you got in any problem let me know. We will try to solve that together.

Links may be useful to find stuff

1. Jruby Activerecord adaptor.
2. My Sample Application
3. RVM

—–

Arun


Follow

Get every new post delivered to your Inbox

Join other followers