views:

1214

answers:

3

Ok, so I have a Rails app set up on DreamHost and I had it working a while ago and now it's broken. I don't know a lot about deployment environments or anything like that so please forgive my ignorance. Anyway, it looks like the app is crashing at this line in config/environment.rb:

require File.join(File.dirname(__FILE__), 'boot')

config/boot.rb is pretty much normal, but I'll include it here anyway.

# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb

RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)

module Rails
  class << self
    def boot!
      unless booted?
        preinitialize
        pick_boot.run
      end
    end

    def booted?
      defined? Rails::Initializer
    end

    def pick_boot
      (vendor_rails? ? VendorBoot : GemBoot).new
    end

    def vendor_rails?
      File.exist?("#{RAILS_ROOT}/vendor/rails")
    end

    def preinitialize
      load(preinitializer_path) if File.exist?(preinitializer_path)
    end

    def preinitializer_path
      "#{RAILS_ROOT}/config/preinitializer.rb"
    end
  end

  class Boot
    def run
      load_initializer
      Rails::Initializer.run(:set_load_path)
    end
  end

  class VendorBoot < Boot
    def load_initializer
      require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
      Rails::Initializer.run(:install_gem_spec_stubs)
    end
  end

  class GemBoot < Boot
    def load_initializer
      self.class.load_rubygems
      load_rails_gem
      require 'initializer'
    end

    def load_rails_gem
      if version = self.class.gem_version
        gem 'rails', version
      else
        gem 'rails'
      end
    rescue Gem::LoadError => load_error
      $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
      exit 1
    end

    class << self
      def rubygems_version
        Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
      end

      def gem_version
        if defined? RAILS_GEM_VERSION
          RAILS_GEM_VERSION
        elsif ENV.include?('RAILS_GEM_VERSION')
          ENV['RAILS_GEM_VERSION']
        else
          parse_gem_version(read_environment_rb)
        end
      end

      def load_rubygems
        require 'rubygems'
        min_version = '1.1.1'
        unless rubygems_version >= min_version
          $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
          exit 1
        end

      rescue LoadError
        $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
        exit 1
      end

      def parse_gem_version(text)
        $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
      end

      private
        def read_environment_rb
          File.read("#{RAILS_ROOT}/config/environment.rb")
        end
    end
  end
end

# All that for this:
Rails.boot!

Does anyone have any ideas? I am not getting any errors in the log or on the page.

-fREW

+1  A: 

My guess would be that you're breaking because of a newer version of the Rails gems on Dreamhost. At least, that's been my issue when things have blown up in something like boot.rb.

Try freezing the gems from your development environment into your vendor/rails directory.

Otto
+2  A: 

I had the same problem on DreamHost. Freezing rails and unpacking all gems got me past it.

rake rails:freeze:gems
rake gems:unpack:dependencies
alex
A: 

Ya - the problem is not really in boot.rb - it's just that boot.rb is where rails is actually loaded.

So you'll get an error like this if you've specified a version of Rails that just doesn't exist on your dreamhost slice. This can happen if you either upgrade your project, start a new project (and forget that you upgraded rails in the meanwhile) or if you're still using an old version of rails and it's now been removed from the dreamhost server that you're on.

To figure out which is is, look in config/environment.rb for the line that'll read something like:

RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION

Then ssh to your dreamhost server and type gem list and see if your version is in the list.

If not, you an try several options. Lets say the version you're using is 2.3.4 To begin with, try: gem install rails -v=2.3.4 then restart. That may be all that is required. If that doesn't work, then try freezing and unpacking the gems (as per the other answer here).

There is also another possibility - that you're actually missing a gem that rails depends on but which is failing silently - eg a dependency on a certain version of rack caught me out once. But you may also have other gem dependencies

If you run rake gems you will be able to list all the gems that your project knows about that it needs - make sure they're installed to begin with.

Then, as a sort of rough smoke-test, try running script/console - if you're missing an important rails gem, script/console won't load and should fail, giving you a notice about the gem you need.

Update: If you're trying to run v 2.3.5, you may also be suffering from this problem: http://stackoverflow.com/questions/1814856/bypassing-rack-version-error-using-rails-2-3-5

In which case you'll need to follow the instructions there.

Taryn East