Trouble upgrading a gem (RedCloth) in my rails app

I am using Passenger and I need to get RedCloth 4.0 to work for my rails app.

Even after following all the different suggestions on the wiki, the app still uses the preinstalled version of RedCloth (3.0.4) instead of my local gem.

Here is what I did.

I installed RedCloth 4 into ~/.gems

I tried setting the GEM_PATH environment variable in environment.rb.

I tried unpacking it into my vendors directory.

Either way, it still uses 3.0.4

Any thoughts?

This problem is due to Rails preloading RedCloth in strange and funky ways for use in its “textilize” methods. It gets loaded before your GEM_PATH command takes effect.

The solution to this seems to be to freeze Rails to your app, as well as force it to only search for gems in your ~/.gems repository.

  1. Make sure you have rails and redcloth installed in ~/.gems

  2. Freeze rails
    $ rake rails:freeze:gems

  3. Only grab personal gems


ENV[‘GEM_PATH’] = File.expand(’~/.gems’)

  1. Restart passenger
    $ touch tmp/restart.txt

Presumably there’s no reason why the GEM_PATH can’t include the global gem repository too, but I had some unexplainable passenger errors until I removed it. You may have better luck than me, but there’s some measure of comfort in relying only on your own gem repository.

If you’re using capistrano for deployment, it’s a simple matter to automate the freezing process without storing the entire rails core in your SCM:


namespace :deploy do
after “deploy:update_code”, “deploy:freeze”

task :freeze do
run "cd #{release_path}; /usr/bin/rake rails:freeze:gems"

(Sorry for the lack of indentation on these forums.)