Rails: request.subdomains calls the undef method to request when in the application controller

I am trying to extract a subdomain in the application controller, for widespread use of the application, thus

@subdomain = request.subdomains(0) 

While this code works on any other controller, in the application controller it gives

 undefined local variable or method `request' for ApplicationController:Class 

an exception.

I am using rails 3.2.2 on Lion.

I took it from a DHH code snippet for basecamp style subdomains -

 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 

What am I missing?

+4
source share
1 answer

When you get this error, this is because you are calling request inside the ApplicationController and not inside the method. Are you sure that the code you showed us is correct?

+3
source

Source: https://habr.com/ru/post/1415872/


All Articles