nice_partials icon indicating copy to clipboard operation
nice_partials copied to clipboard

Locals not working without a block

Open adampal opened this issue 1 year ago • 1 comments

Local variables passed to a partial aren't working as expected unless the render call includes a block.

For example, when doing: <%= render 'shared/box', title: "Some Title" %> The title variable is not available via partial.title.

But if I change the render call to: <%= render 'shared/box', title: "Some Title" do end %>

The variable is now available via partial.title.

I set up a clean Bullet Train app to demo the issue and to confirm it wasn't something I was doing. The dummy repo is here: https://github.com/adampal/np_tester

And the one commit that adds the two versions of the render call is here: https://github.com/adampal/np_tester/commit/16e7f85a555ed316c13b4618624c674aa8c8dc4f

It just adds this to the team show page:

    <div>Rendering a box with a title</div>
    <%= render 'shared/box', title: "Test title" %>
    <div>Rendering a box with a title and a block</div>
    <%= render 'shared/box', title: "Test title" do end %>

This is the team show page with the two different render calls: Screenshot 2024-03-24 at 3 05 33 PM

You can see that the first box has "Your Team's Dashboard" because it's falling back to a default title because the title variable isn't being passed in.

In the second box, the title is correctly displayed.

adampal avatar Mar 24 '24 04:03 adampal

Some additional context, I just discovered that this is only an issue when you're nesting render calls. It all works as expected when calling render directly from the top level template.

adampal avatar Mar 24 '24 05:03 adampal

Fixed in #100. I'm still working on CI and shipping a release, but I think it makes sense to close this optimistically.

kaspth avatar Aug 03 '24 16:08 kaspth