我有一个看起来像这样的控制器:
public gs.GCodeFile Load(string path)
{
try
{
GenericGCodeParser parse = new GenericGCodeParser();
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
return parse.Parse(sr);
}
catch(Exception)
{
return null;
}
}
因为控制器位于模块内,所以使用的策略类是module Guardians
class StudentsController < ApplicationController
def show
@student = Student.find params[:id]
authorize @student, policy_class: StudentPolicy
end
end
end
,这正是我想要的。
但是我现在有另一个控制器:
Guardians::StudentPolicy
这里使用的policy_class是module Teachers
class StudentsController < ApplicationController
def show
@student = Student.find params[:id]
authorize @student, policy_class: StudentPolicy
end
end
end
但是因为show方法本身是相同的,所以理想情况下,我希望对此有所关注。但是,如果我似乎无法做到这一点,就像
Teachers::StudentPolicy
时,它将不再自动调用命名空间策略类。
最干的方法是什么?
答案 0 :(得分:0)
如果您这样创建关注点:
now()
然后将其包含在两个控制器中并清除show动作。