Posts Tagged ‘Rails’

Thinking Sphinx and Frozen Rails

Friday, February 19th, 2010

Here’s the situation: you’re trying to get the thinking_sphinx gem working with your Rails project on your local machine, and it doesn’t work.  In fact, when you follow the installation instructions and require “thinking_sphinx/tasks” in your Rakefile, you can’t even run rake anymore.

Running “rake -T” nets you the following error:

C:\dev\project>rake -T
(in c:/dev/project)
rake aborted!
undefined method ‘map’ for nil:NilClass
C:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile’
(See full trace by running task with –trace)

Here is the issue: in order to talk to your database, Thinking Sphinx is loading its own ActiveSupport.  It loads this ActiveSupport from your machine’s gem list, even if your Rails project is using frozen (vendor) Rails.  If you are getting the error shown above when you attempt to start your server or run rake, it means that your environment.rb specifies a RAILS_GEM_VERSION that is not installed on your machine.

Example?  You might have Rails gem versions 2.3.3 and 2.3.5 installed on your machine, but the frozen Rails in your project’s vendor directory (and thus your project’s RAILS_GEM_VERSION) is 2.3.4.

Now, it would seem that avoiding this type of scenario is the reason you are freezing Rails, but luckily there’s an easy fix.  Just install the missing version of the Rails gem, like so:

C:\>gem install rails -v 2.3.4

Hopefully this saves someone somewhere the headache it gave me.

(in c:/dev/mobd-fleet)
rake aborted!
undefined method `map’ for nil:NilClass
C:/devtools/ruby/lib/ruby/

gems/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile’
(See full trace by running task with –trace)