我要重写Devise:RegistrationController,我需要添加一个before filter身份验证功能,该功能在我的应用程序的BaseController中如何在filter之前添加该功能。我在扩展Devise:RegistrationsController且无法扩展basecontroller时遇到了这个问题
答案 0 :(得分:1)
创建关注点,然后在两个控制器中都包含该关注点:
## app/controllers/concerns/concern_with_the_method_i_want.rb
module ConcernWithTheMethodIWant
def method
return 'This is the method'
end
end
class BaseController < ApplicationController
include ConcernWIthTheMethodIWant
end
class RegistrationController < Devise::RegistrationController
include ConcernWithTheMethodIWant
end
这将使您能够做到:
BaseController.new.method
=> 'This is the method'
Devise:RegistrationController.new.method
=> 'This is the method'