【发布时间】:2021-10-03 16:59:31
【问题描述】:
标题是我的问题。
devise 为我们提供了许多有用的方法,如current_user、authenticate_user! 等。我想知道为什么可以在不包含任何模块的情况下使用它们。
class ApplicationController < ActionController::Base
before_action :authenticate_user!
end
那些方法的定义是here
有人请帮帮我!
【问题讨论】:
-
当您在
routes.rb中使用devise_for时,Devise 会查找您的 ApplicationController 并动态定义方法。如果您想详细了解它的工作原理,您确实需要查看源代码。 -
补充 max 上面所说的:设计,像大多数 gem 一样,使用 Ruby 中的元编程来实现其目标。 Devise 用于为
current_生成动态方法的源代码可见:github.dev/heartcombo/devise/tree/master/lib/devise/controllers
标签: ruby-on-rails devise warden