Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何处理模块命名空间控制器共享的问题_Ruby On Rails_Activesupport Concern - Fatal编程技术网

Ruby on rails 如何处理模块命名空间控制器共享的问题

Ruby on rails 如何处理模块命名空间控制器共享的问题,ruby-on-rails,activesupport-concern,Ruby On Rails,Activesupport Concern,我有一个控制器,看起来像这样: module Guardians class StudentsController < ApplicationController def show @student = Student.find params[:id] authorize @student, policy_class: StudentPolicy end end end 这里使用的策略类是Teachers::StudentPoli

我有一个控制器,看起来像这样:

module Guardians
  class StudentsController < ApplicationController   

    def show
      @student = Student.find params[:id]

      authorize @student, policy_class: StudentPolicy
    end
  end
end
这里使用的策略类是
Teachers::StudentPolicy

但是,由于show方法本身是相同的,理想情况下,我想用一个关注点来解决这个问题。然而,如果我似乎无法做到这一点

authorize@student,policy\u班级:StudentPolicy

从关注点内部调用时,将不再自动调用命名空间策略类


实现这一目标的最干燥的方法是什么?

如果您造成这样的问题:

module Guardians
  class StudentsController < ApplicationController   

    def show
      @student = Student.find params[:id]

      authorize @student, policy_class: StudentPolicy
    end
  end
end
模块学生关注
扩展ActiveSupport::关注点
包括做
行动前:查找并授权学生,仅:[:显示]
结束
私有的
def查找学生和授权
@student=student.find(参数[:id])
如果self.class.name.deconstantize==“教师”
授权@student,policy\u班级:教师::StudentPolicy
其他的
授权@student,政策\类别:监护人::StudentPolicy
结束
结束
结束
然后将其包含在两个控制器中,并清除“显示动作”