Switching Between Ruby Versions on Windows

I had the need to handle multiple Ruby versions on my Windows PC.  I was creating a new Rails app and wanted to use the latest Ruby version, but I also needed to manage apps that used older versions.  Many developers use RVM, but it doesn’t work on Windows – so I needed a different solution.

I found URU and it works great for managing multiple Ruby versions.

I tried installing it by downloading the compressed file and running the executable included, but it didn’t work correctly.  For some reason, it created a new directory, but the directory was empty.

So instead, I used the Scoop method – downloading Scoop and then using it to install URU.

(1) After I installed URU, I added the directory to my PATH (environmental variable) on my PC.

(2) Next, I opened a CMD window, and then specified the bin directories for each Ruby version you want o use.  For example entering this on the cmd line (for each Ruby install):

uru admin add C:\ruby200\bin

(3) Then to switch between Ruby versions you enter the command, including the Ruby version (without periods):

uru 200

This will switch to Ruby 2.0.0.

You can check that you were switched by entering this command to check what version you are using:

ruby -v

The first time that I did this, I just installed the new Ruby version and I received an error telling me that my gemfile specified version 2.4.4, but I was running 2.2.1.  That was weird because when I ran ‘ruby -v’, it told me I was on 2.4.4.

It turns out, I just needed to run ‘bundle install’ to install the gems that were in the app I was trying to run, but not installed for the new Ruby version yet.

For more details on URU commands, you can read this page from the wiki.

Advertisements

Getting ActiveAdmin to Play Nice with Will_Paginate

My app was already using will_paginate extensively and I didn’t feel like changing it all to the Kaminari which ActiveAdmin uses for pagination.

However, somehow I was able to get it to work by thumbing through this ActiveAdmin issue.  I created the initializer suggested by kml with this code:

Kaminari.configure do |config| 
 config.page_method_name = :bonzo # :) 
end

However, when I implemented it, the code recommended for config/initializers/active_admin.rb caused me errors so I removed it.  You may find that you need this code.

Allowing HTML Tags in Form Fields

I wanted to allow my users to be able to include html tags in things they posted.  Originally, I was thinking that this was done as an option to the form field, but it actually is in the view where you display the user content.

In my case, I have this in the form:

<%= f.text_area :content %>

and where you want to display it, just add “.html_safe”, for example:

<%= article.content.html_safe %>

DevKit Missing

The first time I installed RoR, I used EngineYard’s wonderful RailsInstaller (railsinstaller.org), but for my upgrade, I wanted to go to 1.9.2, but they only had packages with 1.8.7 and 1.9.3.  So instead, I just downloaded 1.9.2 and installed it.

One thing I was missing with the DevKit (which I found out through an error message when I was installing my gems again).  So I installed it from http://rubyinstaller.org/downloads/ and then followed the directions on https://github.com/oneclick/rubyinstaller/wiki/Development-Kit.  In the config.yml file generated, I just had to add where my new Ruby installation was (C:/Ruby192).

Pik

Most people who are not on Windows use RVM to manage their Ruby versions, but RVM doesn’t work for Windows.  Instead there’s a great tool called Pik that does the thing.  Pik allows you to switch between different Ruby versions you have on your PC.  I needed this once I went to 1.9.2.

The Github page for Pik is here: https://github.com/vertiginous/pik

The Github page didn’t include a lot of details though.  For more detailed instructions, I found this wonderful tutorial by Ben Hall:
http://blog.benhall.me.uk/2010/08/installing-rails-30-ruby-192-and-pik-on.html