【问题标题】:Active Admin and Devise: current_user and user_signed_in? undefined活跃的管理员和设计:current_user 和 user_signed_in?不明确的
【发布时间】:2014-11-07 14:45:22
【问题描述】:

所以我在ApplicationController 中实现了before_filter,以便检查用户的自定义enabled 属性,如果管理员禁用了他们的帐户,这将终止他们的会话并将他们返回到登录页面。

我一直遇到以下错误:

undefined method current_userundefined method user_signed_in?

我用谷歌搜索了一下,并尝试了 StackOverflow 的其他解决方案(见下文),但没有奏效。

将以下内容添加到application.rb

config.action_controller.include_all_helpers = false

【问题讨论】:

    标签: ruby-on-rails-4 devise activeadmin


    【解决方案1】:

    在敲了几下之后,我记得在 Active Admin 配置文件中阅读了一些内容,active_admin.rb 是关于为管理员用户设置帮助方法的。

    注意:我没有使用 Devise 的默认 User 模型,而是使用 Active Admin 的 AdminUser

    因此,如果您查看 active_admin.rb 文件,您会看到:

    # This setting changes the method which Active Admin calls

    # (within the application controller) to return the currently logged in user.

    config.current_user_method = :current_admin_user

    所以这里 Active Admin 覆盖了 Devise 的 current_user 助手!

    然后我恍然大悟:

    代替current_user,使用:current_admin_user

    而不是user_signed_in?,使用:admin_user_signed_in?

    砰,完成!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-23
      相关资源
      最近更新 更多