Rails 5: content_for and yield not working

216 Views Asked by At

I am having a content_for block in my application.html.erb as below

    <% if alert.present? %>
      <%content_for :inline_alert_display do%>
        <div class="row" data-snackbar>
          <%=render 'components/message', {snackbar_class: 'warning', msg:alert}%>
        </div>
      <%end%>
    <% end %>

and then in sessions/new.html.erb i am calling yield like below

<%= yield :inline_alert_display if content_for?(:inline_alert_display)%>

for what it's worth, i have turbolinks enabled.

But nothing prints.

May be i am missing something, any help to fix this would be great, thanks.

1

There are 1 best solutions below

0
obiruby On

I think you need to reverse it and put ‘yield’ in the template and ‘content_for’ in the view.