Search code examples
ruby-on-railsstimulusjsstimulus-reflex

How to access current_user in stimulus_reflex


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

Solution

  • Ref this,

    Add following line in your reflex class.

    delegate :current_user, to: :connection