post/rails-current-attributes/ #4
Replies: 1 comment
-
I assume the following is bad practice due to lazy loading, but you didn't explain why that's bad. What do you think? class CurrentTeam < ActiveSupport::CurrentAttributes
attribute :team, :team_role, :team_policy
def user
Current.user
end
def role
self.team_role ||= TeamRole.new(user, team)
end
def policy
self.team_policy ||= TeamPolicy.new(user, team)
end
end In use, I reset it for every request, and set CurrentTeam.team in my teams_controller. I use it in views and helpers to control what gets sent to the client (For instance, only the team owner or a site admin gets a destroy button). I use it to be DRY so I can |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
post/rails-current-attributes/
Deep dive into Rails.current_attributes (ActiveSupport::CurrentAttributes)
https://hsps.in/post/rails-current-attributes/
Beta Was this translation helpful? Give feedback.
All reactions