【问题标题】:Rails 3 - Oberserver - Not able to user the Devise @current_userRails 3 - Oberserver - 无法使用设计@current_user
【发布时间】:2010-10-01 02:41:21
【问题描述】:

我正在构建一个 Rails 3 应用程序,并且有一个 Observer...

在观察者中,我需要使用 DEVISE 允许我在我的视图中使用的 current_user var...

如何在 Observer 中使用 current_user.name 或 current_user.id?

谢谢

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 devise


    【解决方案1】:

    创建 User.current 访问器,它设置/读取 Thread.current[:user]

    http://rails-bestpractices.com/posts/47-fetch-current-user-in-models

    【讨论】:

      猜你喜欢
      • 2013-06-10
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      • 2012-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多