Spree - 如何获取当前登录的管理员用户

问题描述:

我正在使用延迟作业,该作业完成后会向请求它的管理员用户发送电子邮件。所以,要做到这一点,我需要知道在Spree::Order模型中启动它的管理员用户是谁。 我试着try_spree_current_userspree_current_user,但他们不工作返回:Spree - 如何获取当前登录的管理员用户

NameError (undefined local variable or method `try_spree_current_user' for #<Spree::Order:0x007f93811d7240>): 
    app/models/spree/order_decorator.rb:30:in `after_cancel' 
    app/controllers/spree/admin/orders_controller_decorator.rb:4:in `cancel' 

你一些如何需要确保管理员可以启动顺序:

# Is this user an admin 
if spree_current_user.admin? 
# Do some delayed job 
# send the email 
# because spree_current_user.id is the one that sends it 
else 
flash[:error] = "You need to be an admin to do this." 
redirect_back_or_default(spree.root_path) 
end 

以上应该做的你想做什么。你需要测试当前用户是否是管理员,然后做他/她需要做的事情。

我相信你的意思是OrdersController?不是型号。