如何在 stimulus_reflex 中访问 current_user

How to access current_user in stimulus_reflex

在此反射中,我想将 lastupdateby 字段设置为 current_user。我一直无法让它工作。我需要做些什么才能反射获得该值吗?对我做错了什么有什么想法吗?如果我硬编码值而不是 current_user 它会起作用。我一定是引用错了。

def toggle
 todo = Todo.find(element.dataset[:id])
 todo.update(completed_at: (todo.completed_at? ? nil : Time.current), lastUpdatedBy: current_user)
end

参考 this,

在你的反射中添加以下行 class。

delegate :current_user, to: :connection