6

I have set up RVM and made individual gemsets for my projects as per the RVM best practices. Now running a test file in TextMate dosen't work and I have read here what to do. The problem is that it won't work because the guide expects me to have just one gemset (they call it "Rails3"). I normally have 2-3 projects open at a time (using different gemsets) so I can't effectively use this approach.

Have any of you solved that problem?

Phrogz
  • 296,393
  • 112
  • 651
  • 745
jriff
  • 1,947
  • 3
  • 23
  • 33

2 Answers2

12

I've found the RVM wrappers method to be very buggy, and as you've discovered it doesn't work at all with gemsets unless you do a lot of tedious setup.

I've had some success using the following script as TM_RUBY:

#!/bin/bash

base_dir=${TM_PROJECT_DIRECTORY:-$PWD}
cd $base_dir
exec $MY_RUBY_HOME/bin/ruby $*

As long as you're in a TextMate project and you have a .rvmrc file in the project root it will run your code in the Ruby version and gemset specified in the .rvmrc. The cd makes sure RVM discovers the .rvmrc.

Put the code above into ~/bin/textmate_ruby_wrapper and then go to Preferences > Advanced > Shell Variables and set TM_RUBY to that same path.

Theo
  • 131,503
  • 21
  • 160
  • 205
  • Man, I've been [saving my upvotes for questions](http://stackoverflow.com/badges/155/electorate), but I gotta spend one on this. Very nice! – Phrogz Feb 09 '11 at 19:17
  • So close! I've tried this solution but get the message: Can't find “~/bin/textmate_ruby_wrapper” on PATH. – Tom Rossi Jan 13 '12 at 15:05
  • 1
    I found adding the line `source ~/.rvm/scripts/rvm` after the shebang made this solution more robust. – siannopollo Jul 30 '13 at 18:09
  • Wow I've been trying to track down a solution and this is one of the few I was comfortable with – Min May 13 '14 at 21:48
0

I've found this solution which is even simpler. Under the TextMate Preferences - Advanced - Shell Variables:

Set your GEM_HOME:

env | grep GEM_HOME | awk '{ sub(/GEM_HOME=/, ""); print }'

Set your GEM_PATH:

env | grep GEM_PATH | awk '{ sub(/GEM_PATH=/, ""); print }'
Tom Rossi
  • 11,604
  • 5
  • 65
  • 96