Rule: erb-no-instance-variables-in-partials
Prevent usage of instance variables inside ERB partials. Using instance variables inside partials can cause issues as their dependency is defined outside of the partial itself. This makes partials more fragile and less reusable. Local variables should be passed directly to partial renders.
A partial is any template whose filename begins with an underscore (e.g. _card.html.erb).
Instance variables in partials create implicit dependencies on the controller or parent view, making partials harder to reuse, test, and reason about. Passing data as local variables makes the partial's interface explicit and self-documenting.
<%= render partial: "posts/card", locals: { post: @post } %><div>
<%= post.title %>
</div><%= render partial: "posts/card" %><div>
<%= @post.title %>
</div>