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

问题描述 投票:1回答:1

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

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'
ruby-on-rails-4 spree rails-activejob
1个回答
1
投票

您需要确保管理员可以启动订单的方式:

# 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?不是模特儿。

© www.soinside.com 2019 - 2024. All rights reserved.