所以我遇到了一个问题,我有两个独立的设计模型(管理员和用户),并且因为我使用的是一个名为Milia的多租户gem,我需要两个应用程序控制器(一个用于Admin之外的租约和租户内的用户一个。问题是我需要从这两个设计模型中访问一个控制器,但我只能从下面的应用程序控制器之一继承该控制器。有没有办法解决这个问题我可以指定哪个用户在使用特定资源的控制器时应该使用哪个应用程序控制器?或者是否有其他解决此问题的方法?
两个应用程序控制器看起来像这样
class AdminApplicationController < ActionController::Base
before_action :authenticate_admin!
end
class ApplicationController < ActionController::Base
before_action :authenticate_tenant!
end
答案 0 :(得分:0)
给你一些灵感:)
class ApplicationController < ActionController::Base
before_action :authenticate_them
def authenticate_them
authenticate_tenant!
end
end
class AdminApplicationController < ApplicationController
before_action :authenticate_them
def authenticate_them
authenticate_admin!
end
end
class AnotherController < ApplicationController
before_action :authenticate_them
def authenticate_them
if admin_signed_in? or tenant_signed_in?
#or whatever other authentication you want
end
end
end