Misha Krul
Misha Krul

Reputation: 397

Rendering a partial in rails, in two separate places, from two different controllers

I've got two controllers, a_controller and b_controller.

In each controller I am rendering a partial from a shared folder located in app/views/admin/shared.

The partial in a_controller is being rendered like this:

<div id='status-change'>
    <% if !@item_a.has_been_used_in_production? %>
        <%= render partial: 'admin/shared/partial_name', locals: { item: @item_a, f: f } %>
    <% end %>
</div>

And the partial in b_controller is being rendered similarly, but with a different variable being passed in.

<div id='status-change'>
    <% if !@item_b.has_been_used_in_production? %>
        <% render partial: 'admin/shared/partial_name', locals: { item: @item_b, f: f } %>
    <% end %>
</div>

The partial is rendering properly from a_controller, but is not rendering at all from b_controller. I'm not getting any error messages on either of the pages. If I type anything outside of the render space, but inside of the if-statement, I can see the text. Likewise, I can copy and paste all of the code from inside the partial, and put it inside of the if statement, and it will display properly. It just doesn't seem to want to render directly from the partial.

Upvotes: 0

Views: 703

Answers (1)

yzalavin
yzalavin

Reputation: 1836

Should be with an equal sign: <%= render ... %>.

<% %> executes Ruby code, but does not render a result. Whereas <%= %> executes and renders.

Upvotes: 1

Related Questions