我试过这样的事情
class SomeController < ApplicationController
before_action :something, if: request.subdomain == "specific"
end
但是在这里我无法访问请求对象而且它会抛出错误。
undefined local variable or method `request' for SomeController:Class
有人可以建议我如何实现这个目标吗?
答案 0 :(得分:1)
使用proc,
class SomeController < ApplicationController
before_action :something, if: proc { |c| c.request.subdomain == "specific" }
end
答案 1 :(得分:0)
你可以做类似的事情
before_action :something
def something
if request.subdomain == "specific"
your code
end
end