I recently had a problem with rake gems:install with a fresh rails app. Rakefile bootstraps the full rails environment, including plugins, controllers, etc. Some of the code getting executed depended on a gem, but I was running “rake gem:install” to install those gems. A circular “chicken or the egg” problem!

Here was my solution, which I put in environment.rb


unless $0 =~ /rake/
 # ... require code that relies on certain gems
end

actionmailer ActionView ActiveRecord activesupport agile ajax alphadecimal audio autotest BDD blocks capistrano ssh ruby console controller css dashboard widget delegate dog puppy naming name DRM email obfuscation exceptions factories factories-and-workers factory pattern filemerge find and replace finder fink fixtures fun functional testing gem gems git google maps haml helper helpers imagemagick install Intertrust irb javascript jquery jrails logo macro math meetup model openssl OS X patch Pioneer Electronics plugin polymorphism project management prototype.js rails rails gotcha rails,patch,validations railsconf rake rmagick RSA encryption ruby ruby on rails script scrum scrum lessons rails scrumninja shoulda subversion SyncTV TDD testing textmate tips tricks unique hashes unix shell validation view yaml zebra stripes