【问题标题】:Rails/Passenger sub URI errorRails/Passenger 子 URI 错误
【发布时间】:2010-08-31 23:09:24
【问题描述】:

我正在尝试使用乘客 2.2.15 将 Rails 3.0.0 应用程序部署到子 URI。

我相信我已对我的 http.conf 进行了正确的 RailsBaseURI 更改,已将子 URI 符号链接到我的应用程序的公共目录,并将以下代码行添加到 environments/production.rb

config.action_controller.relative_url_root = "/sub_uri"

在 rails3.0.0 之前,我已经多次这样做了。也就是说,该应用程序不会启动。它失败并出现以下乘客错误:

Error Message: wrong number of arguments(1 for 0)

Exception class: ArgumentError

/usr/lib/ruby/gems/1.8/gems/actionpack-3.0.0/lib/action_controller/railtie.rb 54 in `relative_url_root='

passenger 2.2.15 和 rails 3.0.0 之间是否存在影响子 URI 的不兼容?

非常感谢您帮助解决此错误。

【问题讨论】:

  • 错误说你给它 1 个参数而不是预期的 0 让我认为他们不再让你设置 relative_url_root。编辑:经过调查,似乎 setter 已被贬低,现在被视为环境变量:ENV['RAILS_RELATIVE_URL_ROOT']

标签: ruby-on-rails ruby-on-rails-3 passenger


【解决方案1】:

setter 已折旧,在actionpack/lib/action_controller/railtie.rb 中找不到。

如此处所示 (actionpack/lib/action_controller/depreciated/base.rb):

module ActionController
  class Base
    # Deprecated methods. Wrap them in a module so they can be overwritten by plugins
    # (like the verify method.)
    module DeprecatedBehavior #:nodoc:
      def relative_url_root
        ActiveSupport::Deprecation.warn "ActionController::Base.relative_url_root is ineffective. " <<
          "Please stop using it.", caller
      end

      def relative_url_root=
        ActiveSupport::Deprecation.warn "ActionController::Base.relative_url_root= is ineffective. " <<
          "Please stop using it.", caller
      end
    end
  end
end

actionpack/lib/action_controller/metal/compatibility.rb 中你可以看到它的setter 是一个ENV 变量:

self.config.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']

所以需要设置ENV变量:RAILS_RELATIVE_URL_ROOT="/sub_uri"

【讨论】:

  • 这似乎与最终的 rails3 版本没有任何关系。
  • 为我工作。使用 Rails 3.0.0 和乘客 3.0.0。谢谢。
【解决方案2】:

设置环境变量添加:

SetEnv RAILS_RELATIVE_URL_ROOT /sub_uri

到您的 apache 配置的 VirtualHost 部分(或类似部分),然后确保通过重新启动 apache 和乘客来读取它。

cd <your_rails_project>
sudo apache2ctl graceful
touch tmp/restart

【讨论】:

    猜你喜欢
    • 2019-03-23
    • 2015-01-16
    • 1970-01-01
    • 2013-06-14
    • 2012-02-01
    • 2016-06-21
    • 1970-01-01
    • 2012-08-23
    • 2015-10-30
    相关资源
    最近更新 更多