If a partial is rendered, and receives 2 local variables "name" and "environment":

# arbitrary show view

<%= render partial: "sports_team/details_and_performance", locals: { name: name, environment: :self } %>

And that partial renders a ViewComponent that receives 2 arguments like so:

# actual content of the partial
# implicitly passing arguments to "name" and "environment"

 <%= render(SportsTeam::Performance::Component.new(name:, environment:)) %>

How is it possible for the ViewComponent to receive "name" and "environment" without explicitly passing the local variables of the partial to the ViewComponent?

I imagine there must be some sort of scope related to the partial, but I've never seen a local variable of a partial "magically" passed in this capacity, without being explicitly passed.

I would expect at a minimum for the ViewComponent to be rendered as such:

# expected content of the partial
# explicitly passing arguments to the "name" and "environment"

 <%= render(SportsTeam::Performance::Component.new(name: name, environment: environment)) %>

I've already searched for solutions on google, chatGPT, and rails guides, though the complexity of this scenario renders poor results.

0

There are 0 best solutions below