我有这段代码:
class ApplicationController < ActionController::Base
def authenticate_user!(*_args)
super
end
end
在authenticate_user!
我致电super
,我应该从authenticate_user!
拨打ActionController::Base
,这是一个抽象类。
我无法在authenticate_user!
内找到ActionController::Base
,所以我想有一些元编程涉及(?)。
来自Devise的authenticate_user!
如何在ActionController::Base
结束?或者在super
中使用ApplicationController
调用的任何其他方法?
答案 0 :(得分:0)
authenticate_user!
是由devise
动态构建的ID的方法,因此您必须使用补丁devise
。控制器和视图中都有助手,这可能是您没有按ActionController::Base
如果您需要覆盖功能,则需要修补此课程:https://github.com/plataformatec/devise/blob/88724e10adaf9ffd1d8dbfbaadda2b9d40de756a/lib/devise/controllers/helpers.rb#L148
您可以通过定义自己的方法来覆盖authenticate_user!
方法。首先,您必须创建目录lib/devise/controllers
并添加一个名为helpers.rb
的文件,您可以添加:
模块设计 模块控制器 模块助手
module ClassMethods
def authenticate_user!
# if something
# do something
# else
super
# end
end
end
如果您没有使用devise
,请发表评论,我会删除此答案