I can’t understand this snippet from https://rubyonrails.org/ (the example model):
class Article < ApplicationRecord
belongs_to :author, default: -> { Current.user }
[...]
end
who is Current.user
? How it works? Can you point me to relevant docs?
thank you,
Francesco
Here’s a writeup: Rails Current Attributes: Usage, Pros and Cons - Mintbit
It’s a way to have attribute sharing across different contexts. I believe it will even work if the app is running across multiple servers in a sharded deployment setup. It is also thread-safe.
Walter
1 Like
holy craps! Big stuff! Thank you so much,
Francesco