I'm curious how Rails 5 renders partials and if there's a gotcha that I'm not aware of. I have two partials on my page, one that is rendered as part of the html and the other that renders inside the success callback of an ajax request. However, when I refresh the page, the partial inside the ajax request is actually being rendered even when the ajax request is not fired, and EVEN when the call to render the partial is commented out.
I had always assumed that partials render at the time the line of code is run.
Here is the relevant code:
$('body').on("click", ".notif-popup-container", function() {
$.post(
"/notifications/read",
{ notif_id: notifId },
).done(function(data) {
$('#notifUnreadCount').html(data.unread_notifs);
var popover = $('#notificationsBell').data('bs.popover');
popover.config.content = $('.notifications-list').html();
})
$('.notifications-list').html("<%= j (render partial: 'notifications/partials/test_partial') %>"); // this never fails to render, even when commented out
})
<div style="display:none" class="notifications-list">
<%= render 'notifications/partials/popover_notifications' %>
</div>
Here is the console output image. As you can see _popover_notifications.html.erb renders as it should, but then my _test_partial.html.erb also renders, which it shouldn't, since the click handler it's in was not fired.
Any insight appreciated.