我正在尝试以这种方式提取应用程序 Controller 中的子域,以供应用程序广泛使用,
@subdomain = request.subdomains(0)
虽然此代码适用于任何其他 Controller ,但在应用程序 Controller 中它会抛出一个
undefined local variable or method `request' for ApplicationController:Class
异常(exception)。
我在 Lion 上运行 rails 3.2.2。
我从 DHH 的 basecamp 样式子域的代码片段中借用了它 -
class ApplicationController < ActionController::Base
before_filter :set_current_account
private
def set_current_account
@current_account = Account.find_by_subdomain!(request.subdomains.first)
end
end
我错过了什么?
最佳答案
当您收到该错误时,它正在发生,因为您正在调用 request
里面 ApplicationController
的类而不是方法内部。您确定您向我们展示的代码是正确的吗?
关于ruby-on-rails - Rails : request. 子域在应用程序 Controller 中引发请求的 undef 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10874673/