Archive for July, 2009

Using rails.vim with JRuby

July 23rd, 2009 No comments

I spent this evening fiddling around with rails.vim and JRuby.  I have some Java code that I’d like to use with Rails, so I’m using JRuby (also, JRuby seems to hate Windows slightly less than MRI).  Anyway, this is really about using vim to edit Rails code. I installed rails.vim and found that it was hard-coded to use plain old Ruby. Assuming that jruby.bat (or jruby, I guess) is on your system path, all you need to do is modify the app_ruby_shell_command in autoload/rails.vim like this:

function! s:app_ruby_shell_command(cmd) dict abort
  if self.path() =~ '://'
    return "jruby.bat ".a:cmd
    return "jruby.bat -C ".s:rquote(self.path())." -S ".a:cmd

Basically, just change “ruby” to “jruby.bat” and add the -S parameter.

The -S flag is important. Otherwise, it seems JRuby’s implementation of the -C flag is a little buggy. For example, almost any script/ command will fail:

>jruby -C c:\path\to\rails\app script/generate
C:/Program Files/jruby-1.3.1/bin/../lib/ruby/1.8/pathname.rb:711:in `relative_path_from': 
        different prefix: "C:/" and "C:\\path/to/rails/app" (ArgumentError)
        from C:/Program Files/jruby-1.3.1/lib/ruby/gems/1.8/gems/rails-2.3.3/lib/rails_generator/lookup.rb:110:in 

Everything seems to be working well now. Yay.

Categories: jruby Tags: