0

当我从我的应用程序目录中运行 rackup 时,它工作正常:

walkraft@li234-166:~/discourse$ rackup config.ru
Flushing redis (development mode)
/home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require': iconv will be deprecated in the future, use String#encode instead.
/home/walkraft/discourse/vendor/gems/message_bus/lib/message_bus.rb:130: warning: already initialized constant ENCODE_SITE_TOKEN
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9292, CTRL+C to stop

但是,如果我尝试从这个目录之外运行 rackup:

walkraft@li234-166:~$ rackup discourse/config.ru
/home/walkraft/discourse/config/application.rb:7:in `require': cannot load such file -- ./lib/discourse_plugin_registry (LoadError)
        from /home/walkraft/discourse/config/application.rb:7:in `<top (required)>'
        from /home/walkraft/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/walkraft/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/walkraft/discourse/config/environment.rb:2:in `<top (required)>'
        from /home/walkraft/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/walkraft/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/walkraft/discourse/config.ru:2:in `block in <main>'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/builder.rb:51:in `instance_eval'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/builder.rb:51:in `initialize'
        from /home/walkraft/discourse/config.ru:in `new'
        from /home/walkraft/discourse/config.ru:in `<main>'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/builder.rb:40:in `eval'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/builder.rb:40:in `parse_file'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/server.rb:200:in `app'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/server.rb:304:in `wrapped_app'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/server.rb:254:in `start'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/server.rb:137:in `start'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/bin/rackup:4:in `<top (required)>'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/bin/rackup:19:in `load'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/bin/rackup:19:in `<main>'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:14:in `eval'
        from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:14:in `<main>'

当我不在根目录中时,如何运行 rackup?

4

2 回答 2

5

如果您不想手动到 Discourse 根文件夹,那么为什么不直接在 rackup文件cd中添加一个修复:config.ru

# Insert as first line in config.ru
Dir.chdir(File.dirname(File.expand_path(__FILE__)))
于 2013-02-12T13:33:42.223 回答
1

实际上,这不是问题rackup; 你的代码有问题。

你有

require './lib/discourse_plugin_registry'

某处。这并不理想。它应该是这样的:

require File.expand_path('../../lib/discourse_plugin_registry', __FILE__)

您拥有它的方式,它显式地使用当前目录,并且无论您做什么rackup,直到您更改当前目录 - 它都不起作用。

于 2013-02-12T13:44:52.610 回答