Always I am indebted.

Before_save is called when the yyy column of the Xxxxxx model is changed as shown below. At that time, the current userid is passed, the user is specified by the userid, and a part of the value is written to another model. I would like to do the flow.

At this time, even if I put a value in session or params, I could not call it on the model side, and I googled if I could pass it in this before_save, but I could not find it well ....

It doesn't matter if it is a reference site, so I would appreciate it if you could teach me the appropriate method.
Thank you.

def update
   Xxxxxx.update (aaa: aaa, yyy: yyy)

# model
class Xxxxxx

Amazon Linux release 2 (Karoo)
Rails 5.2.3
Ruby version: 2.6.1

  • Answer # 1

    There is no choice but to pass it as an argument.
    Xxxxxx.update (aaa: aaa, yyy: yyy)
    In front of
    Xxxxxx.set_by_ (current_user)
    Do you set it in advance like
    Xxxxxx.update_with_ (current_user, aaa: aaa, yyy: yyy)
    Is it passed as and update_with_ (to set the value with: aaa,: yyy?