在我已经扩展了Devise:registrationsController的类中从basecontroller的过滤器之前添加

时间:2019-05-16 15:55:41

标签: ruby-on-rails ruby devise

我要重写Devise:RegistrationController,我需要添加一个before filter身份验证功能,该功能在我的应用程序的BaseController中如何在filter之前添加该功能。我在扩展Devise:RegistrationsController且无法扩展basecontroller时遇到了这个问题

1 个答案:

答案 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'