views:

455

answers:

4

I'm investigating a rails app - the prod server has two version of a specific gem installed, how can I tell which version the prod app is using?

+1  A: 

Try using script/about. Your config/environment.rb also has information about it.

In your config/environment.rb you can specify which version of a particular gem the application should use. However if you have multiple versions of a gem installed on your machine and you do not specify the version, the latest version of that gem will be used by the application.

Waseem
A: 

There probably is a more direct way to find this out, but if you load up a console and require a specific version like so:

gem 'RedCloth', '3.0.4'

It will tell you what version is already activated:

=> Gem::LoadError: can't activate RedCloth (= 3.0.4, runtime) for [], already activated RedCloth-4.2.2
dasil003
A: 

script/about will tell you what versions of the core Rails and Rack gems you're using, but not anything else. Ideally, if you look in config/environment.rb, there should be a section that looks like this:

# Specify gems that this application depends on and have them installed with rake gems:install
# config.gem "bj"
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
# config.gem "sqlite3-ruby", :lib => "sqlite3"
# config.gem "aws-s3", :lib => "aws/s3"

With any luck, the author of the app will have included any required gems and versions there. However, the versions are optional in this file, and ultimately nothing stops an inexperienced developer from just slapping a require 'rubygems'; require 'some_random_thing' at the top of any given file.

If you see that a gem is being required, but no version is specified, you can type gem list to see all the versions of all the gems on the system. By default, it will be using the latest one available.

John Hyland
Does your script/about tell you about gems? Mine just tells me what version of ruby, rails and environment I'm using.
BJ Clark
rails is a gem...
Jongsma
Right, Rails (and Rack) are both gems, and script/about will tell you what versions of them are running, along with the core Rails stuff (ActiveSupport, etc) but it won't tell you about any other gems. Sorry if that wasn't clear.
John Hyland
+2  A: 

rake gems will print out what gems, dependencies, and versions are installed, frozen, etc.

BJ Clark
This will only work if the gem as been specified in the environment.rb file. If the developer just required it somewhere, rake gems won't work.
John Hyland
(Or in one of the config/environments/* files, depending on your RAILS_ENV.)
John Hyland