-
Notifications
You must be signed in to change notification settings - Fork 15
current_user helper in components? #21
Comments
Current attributes can be a solution. More info here: |
@skyksandr thank you, but I'd prefer not to use them. |
@rosendi currently, we're explicitly passing in the values we need to render our components. I'd be curious to hear what you come up with on your end, though. |
Closing this issue due to staleness. Feel free to reopen if desired ❤️ |
I think we should find a way :-) Technically yes - we have to pass all the values (props) we need to render a component, but helpers are more like utilities. In React I would import them and use directly:
Currently if I define a helper in a controller, I have to compute its value and explicitly pass it via attributes. Let's say I have a polymorphic controller (real-world example) for comments. Users can comment posts and images.
My comment's component should be decoupled from post, image, etc. Currently I do:
but I think this way should work too:
and the html of the comment's component then would be:
|
@joelhawksley Hello! It's been a while. Do you still pass all helpers explicitly? It sounds like a non-rails way to pass all current_* such as current_user, current_organization, current_project, etc.. |
@rosendi currently, we do inject the current state explicitly, as doing so enables us to change that state in unit tests. You can also use the |
How could I make
current_user
available in all components without passing it each time?include ApplicationHelper
doesn't work.P.S. I use Sorcery.
The text was updated successfully, but these errors were encountered: