gpt4 book ai didi

ruby-on-rails - 覆盖 DeviseController 基类 - Rails 4,Devise 3

转载 作者:数据小太阳 更新时间:2023-10-29 07:01:01 25 4
gpt4 key购买 nike

我正在尝试覆盖 Devise 方法 set_flash_message .设计文档涵盖如何 override controllers for the various submodules .

但是这个特定的方法位于 DeviseController 中,所有模块的类。

文档(wiki 和内联)没有说明如何实现这一点,所以我不确定如何最好地进行。我相信最好的方法是简单地重新打开类并根据需要修改方法,并且我在 /lib 中放置了一个文件来达到这个效果。然而,它似乎先于 Devise 被加载,导致错误涌现。

NameError in Devise::RegistrationsController#new
undefined local variable or method `require_no_authentication' for #<Devise::RegistrationsController>

DeviseController 的复杂父定义也可能产生净负面影响:

class DeviseController < Devise.parent_controller.constantize

想法?

最佳答案

Devise.parent_controllerdevise/devise.rb 中的 Devise 模块定义中定义。 Luckily, it has mattr_accessor declared ,因此您可以自己设置值(默认值为“ApplicationController”)。在应用程序初始化过程中的某个时间执行此操作可能最有意义,例如,与 initializers/devise.rb 中的其余 Devise 配置一起执行。

关于ruby-on-rails - 覆盖 DeviseController 基类 - Rails 4,Devise 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21769980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com