Skip to content

Using pundit in view components #2149

Answered by boardfish
leorseligmann asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @leorseligmann! Generally, current_user constitutes global state. Within the gem itself, we make a priority of either making explicit where global state is necessary (particularly demonstrated by how helpers are managed), or avoiding it entirely. But components, as with plain old Ruby objects, should also seek to provide a good interface to their consumers.

Injecting companies externally would give you all the benefits of dependency injection and avoiding global state, but if this is something you're using quite widely as a pattern, then it may also be something you might like to consider.

A halfway house could be defaulting to that:

# Might need to go in a before_render callback if c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by leorseligmann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants