Trouble upgrading a gem (RedCloth) in my rails app


#1

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?


#2

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

config/environment.rb

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

  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:

config/deploy.rb

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

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

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