2017-12-06 5 views
0

나는이요청 하위 도메인이있는 조건부 콜백입니다. 그것은 가능한가?

class SomeController < ApplicationController 
    before_action :something, if: request.subdomain == "specific" 


end 

처럼 뭔가를 시도했지만 여기에 내가 요청 개체에 액세스 할 수 있으며 오류를 던지고.

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

누군가 내가 이것을 어떻게 얻을 수 있는지 제안 할 수 있습니까? something`는 보석에서 콜백입니다 :

답변

1

사용 PROC 것처럼`으로 가능하지 내 경우

class SomeController < ApplicationController 
    before_action :something, if: proc { |c| c.request.subdomain == "specific" } 


end 
+0

은 많은 도움이됩니다. 감사. 'c'가 포함하고있는 Class 객체를 설명 할 수 있습니까 ?? –

+1

c는 somecroller의 개체 인스턴스입니다. –

0

당신은,이

before_action :something 

def something 
    if request.subdomain == "specific" 
    your code 
    end 
end 
+0

아니를, 뭔가를 할 수 있습니다. –