ruby-on-rails - Rails : request. 子域在应用程序 Controller 中引发请求的 undef 方法

标签 ruby-on-rails subdomain

我正在尝试以这种方式提取应用程序 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/

相关文章:

java - 使用 Tomcat 允许子域 session cookie 的最佳方式

html - 站点地图 - 子域上的 Wordpress 站点

asp.net - 用于单点登录的表单例份验证 ReturnUrl 和子域

Azure 通配符子域

jquery - Rails ajax 文件上传 (remotipart)

ruby-on-rails - 如何从 Rails 应用程序中的不同 View 访问模型数据

ruby-on-rails - Rails 3. Kaminari 显示分页链接但不更改记录

ruby-on-rails - 数组不返回最频繁的值

apache - 使用 htaccess 将安全域重定向到安全子域

ruby-on-rails - Action Controller ::参数缺失