Rails应用程序启动失败?

时间:2009-08-18 01:56:52

标签: ruby-on-rails

我有一个供应商提供的应用程序我似乎无法在我的本地Mac上启动它们...我收到以下错误。任何人都知道我能做些什么才能使这件事发挥作用。

Apu:app Apu$ script/server
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails 2.2.2 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
/Users/Apu/.gem/ruby/1.8/gems/rails-2.2.2/lib/commands/servers/mongrel.rb:57:in `initialize': No such file or directory - /Users/Apu/Documents/GDB_Parent/scr/GDB/app/log/development.log (Errno::ENOENT)
    from /Users/Apu/.gem/ruby/1.8/gems/rails-2.2.2/lib/commands/servers/mongrel.rb:57:in `open'
    from /Users/Apu/.gem/ruby/1.8/gems/rails-2.2.2/lib/commands/servers/mongrel.rb:57
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    from /Users/Apu/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
    from /Users/Apu/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
    from /Users/Apu/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
    from /Users/Apu/.gem/ruby/1.8/gems/rails-2.2.2/lib/commands/server.rb:49
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    from script/server:3

4 个答案:

答案 0 :(得分:3)

看起来无法创建文件/Users/Apu/Documents/GDB_Parent/scr/GDB/app/log/development.log。日志目录是否存在,您是否有权写入它?

答案 1 :(得分:1)

  1. 确保您的应用根目录中存在日志目录,否则创建日志目录。
  2. 在运行您的应用服务器之前触摸development.log

答案 2 :(得分:0)

检查适当的环境文件(environment.rb和推测的development.rb):

config.log_path = ...

很难解析错误路径中Rails根目录的位置,但我怀疑他们正在使用log_path配置选项来覆盖默认日志路径(./log/*.log),并且Rails吓坏了因为找不到日志文件。

如果删除该选项(或更改现有日志文件的路径),则应解决问题。

答案 3 :(得分:0)

我发现这个错误非常烦人。事实上,我注意到即使我创建文件,它仍然是空的。每次我检查一个新项目,我遇到了这个问题。为了解决这个问题,我编写了一个初始化程序,它将LogTrailer.initialize方法别名化,如果不存在则创建该文件。我的代码如下。

module Rails
  module Rack
    class LogTailer

      #
      # Override this method so that we can make sure the file it wants is there 
      # and we don't get errors on startup.
      #
      alias_method :original_initialize, :initialize
      def initialize(app, log = nil)

        if (log.nil?)
          path = Pathname.new(EnvironmentLog).cleanpath

          File.open(path, 'w') if !File.exists?(path)
        end

        original_initialize(app)
      end
    end
  end
end