Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do you reference current_user with stimulus_reflex?

spacerobotTR asked in General

Trying to slightly build off the stimulus reflex dynamic forms checkbox lesson. I wanted to add the current_user id to the lastUpdateBy field when the checkbox is checked. I have not been able to get it to work though. 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
Reply

I didn't realize you had to delegate the current_user. per this: https://docs.stimulusreflex.com/authentication

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,969+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.