我正在使用延迟作业,该作业在完成后会向请求它的管理员用户发送电子邮件。所以,要做到这一点,我需要知道谁是在Spree::Order
模型中启动它的管理员用户。我尝试过使用try_spree_current_user
和spree_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'
您需要确保管理员可以启动订单的方式:
# 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?不是模特儿。