Showing posts with label rails. Show all posts
Showing posts with label rails. Show all posts

Wednesday, 24 December 2008

On the Rails merger with Merb

I think overall it will be a good thing.

There obviously are a lot of common goals between the two frameworks but I'm more interested in how they merge some of the more controversial differences. Both teams have already mentioned modularity and internal APIs as something that Rails is going to adopt, but what about some of the smaller differences?
Some of the more difficult issues to be resolved might be:
  • Merb's requirement for an explicit call to render or display - will that be optional?
  • Merb's mailer and exception handling - Merb way is probably superior
  • Rails' extensive use of monkey patching and magic versus Merb's preference for code simplicity
  • Rails' use of test/unit versus Merb's RSpec preference - will all of rails internal tests be rewritten in RSpec?
  • slices versus engines - support both??
None of these issues are huge and insurmountable but there are a lot of differences that will have to be debated. Will it be a full or partial buy-in to the Merb philosophy by the Rails team? If it is a full buy-in, Rails backward compatibility will probably suffer. If Rails 3.0 is only a partial merge of the Merb way, merbists may look at Rails 3.0 as a watered-down bastardization of Merb and just continue using Merb 1.x.

I'm certainly looking forward to seeing what they come up with!

Saturday, 3 February 2007

Using Rails with JRuby

In this post I'm going to discuss how to get a rails application running using JRuby. It's not actually not that difficult to just get it running. (The real difficulties arrive when you get to databases and other areas of rails that arent fully covered by JRuby) I'm only going to be launching the application using the WEBrick server at script/server. If you were putting this into production mode you would want to use one of the many many deployment solutions like using glassfish, tomcat and stuff like that. I'm not going to get into that stuff in this post. WEBrick is good enough for development work and as a first step.

If you don't already have JRuby installed, have a look at my previous post.

If you've just installed JRuby and stroll into a rails application and type
# jruby script/server
You will get this error
Cannot find gem for Rails ~>1.2.1.0:
Install the missing gem with 'gem install -v=1.2.1 rails', or
change environment.rb to define RAILS_GEM_VERSION with your desired version.
This is what I did and I was stumped by it at first because I already had version 1.2.1 or rails installed on my system. What was wrong with JRuby? Why didn't it realise this?

I then discovered that actually JRuby has its own gem system. You need to install rails as a JRuby gem.

Check out http://www.headius.com/jrubywiki/index.php/JRuby_on_Rails for more detail but basically you use

# $JRUBY_HOME/bin/gem install rails -y --no-ri --no-rdoc

to install rails as a gem for JRuby. This should produce this (assuming you have JRUBY_HOME defined):
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rails-1.2.1
Successfully installed rake-0.7.1
Successfully installed activesupport-1.4.0
Successfully installed activerecord-1.15.1
Successfully installed actionpack-1.13.1
Successfully installed actionmailer-1.3.1
Successfully installed actionwebservice-1.2.1
Great!

Now go into a rails app:
$ cd ~/webprojects/mygreatnewrailsapp.com
$ jruby script/server
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2007-02-03 13:48:03] INFO WEBrick 1.3.1
[2007-02-03 13:48:03] INFO ruby 1.8.5 (0) [java]
[2007-02-03 13:48:03] INFO WEBrick::HTTPServer#start: pid=29324282 port=3000

Woohoo!
Go http://localhost:3000/ in your browser and if its a brand new application you should see the "Welcome to Rails page"

WEBrick is OK, but what about Mongrel?
While Mongrel is mostly Ruby, but it also contains some C (for speed reasons). JRuby can't do anything with C so for now Mongrel is out (More about that here.). What is necessary is the conversion of the C components in Mongrel to Java but as far as I know no-one has done that yet.