Author Archives: Pascal Ehlert

Using vim with the Ruby Version Manager

Just like many other people, I joined the recent hype of going back to vim after using Textmate for a long time.
I have to say it’s good to be back and it’s great using vim’s great capabilities with Ruby development.

However, I stumbled upon one thing that has really caused me trouble, and there is not much solution on the internet.
When using the rails-vim with rvm, it never seemed to call the right ruby version, resulting in missing gems etc. However, when starting a shell via “:shell”, everything worked as expected.

Other people have had this issue as well and some of them created RVM vim plugins which kinda solved the problem. Sorry guys, although your plugins may have other nice features, you have totally missed the point.

After some investigation in the vim source code which is very well written, I figured out a bit which I could have easily found in the help file.. Using “:!command” runs the command in a non-interactive shell by default, while “:shell” obviously opens an interactive shell.

The problem with non-interactive shells is that they don’t load their ~/.(bash, zsh, whatever)rc files (as pointed out here), the place where for most users, RVM is being initialized.

Thankfully, the solution to this is very simple. Just add this to your ~/.vimrc file, and “:!ruby -v” should show you your default Ruby version selected in RVM:

set shellcmdflag=-ic

Capistrano with Rails 3 and bundler

Today I tried to deploy a new Rails 3 project using beloved Capistrano.

When it came to installing the gems after the deployment process however, although I found an almost ready to use task for Capistrano, I stumbled upon a severe issue:
Whenever bundler tried to install gems, I was automatically asked for my root password.

Given that interactive prompting is nasty with Capistrano, and I don’t want a single application’s gems installed system-wide anyway, I did a little research and found a hardly documented way to install the gems inside the Rails application directory (what used to be vendor/gems).

Apparently you don’t use vendor/gems anymore, but vendor/bundle. The idea is almost the same though.
Here is the task you need, in order to make bundler unpack the gems there:

namespace :bundler do
  set :bundle_dir, File.join(release_path, 'vendor/bundle')
 
  task :create_symlink, :roles => :app do
    shared_dir = File.join(shared_path, 'bundle')
    run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{bundle_dir}")
  end
 
  task :bundle_new_release, :roles => :app do
    bundler.create_symlink
    run "cd #{release_path} && bundle install #{bundle_dir} --without test"
  end
end
 
after 'deploy:update_code', 'bundler:bundle_new_release'