How to access current_user in stimulus_reflex

576 views Asked by At

In this reflex I want to set the lastupdateby field to the current_user. I haven't been able to get it to work. Is there something I need to do to get that value in a reflex? Any thoughts on what I am doing wrong? If I hard code the value instead of current_user it works. I must just be referencing it wrong.

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

There are 1 answers

0
Salil On BEST ANSWER

Ref this,

Add following line in your reflex class.

delegate :current_user, to: :connection