【问题标题】:How to get the controller name and the current_user name in model -----ruby on rails如何获取模型中的控制器名称和current_user名称-----ruby on rails
【发布时间】:2014-07-21 09:50:59
【问题描述】:

如何获取模型中的控制器名和current_user名 我想将这些信息保存在 operation_logs 表中

现在我编写这些代码:

module RecordOperation
  extend ActiveSupport::Concern
  included do
    after_update :record_operation
    before_destroy :record_operation
    after_create :record_operation
    def record_operation

    end
end

【问题讨论】:

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


    【解决方案1】:

    要在 shell 中获取用户名,只需尝试使用 ENV:

     ENV[ 'USER' ] # => 'username'
    

    获取控制器名称尝试使用:

     self.class.to_s.underscore # => 'application_controller'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多