    # File lib/phusion_passenger/app_process.rb, line 59
            def self.detect_framework_version(app_root)
                    if File.directory?("#{app_root}/vendor/rails/railties")
                            # NOTE: We must check for 'rails/railties' and not just 'rails'.
                            # Typo's vendor directory contains an empty 'rails' directory.
                            return :vendor
                    end

                    environment_rb = File.read("#{app_root}/config/environment.rb")
                    environment_rb =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
                    gem_version_spec = $1
                    if gem_version_spec.nil?
                            return nil
                    end

                    search_results = search_gem('rails', gem_version_spec)
                    found_version = search_results.map do |x|
                            x.version.version
                    end.sort.last
                    if found_version.nil?
                            # If this error was reported before, then the cache might be out of
                            # date because the Rails version may have been installed now.
                            # So we reload the RubyGems cache and try again.
                            Gem.clear_paths
                            search_results = search_gem('rails', gem_version_spec)
                            found_version = search_results.map do |x|
                                    x.version.version
                            end.sort.last
                    end

                    if found_version.nil?
                            raise VersionNotFound.new("There is no Ruby on Rails version " <<
                                    "installed that matches version \"#{gem_version_spec}\"",
                                    gem_version_spec)
                    else
                            return found_version
                    end
            end