"> Then, in my opinion, this works correctly: ...">

Using content_for inline in Rails

I have it in my layout

<body class="<%= yield :body_class %>">

Then, in my opinion, this works correctly:

<% content_for(:body_class) do %>some-class<% end %>

But this is not so:

<% content_for(:body_class) { 'some-class' } %>

Does anyone know why?

Btw, this is Rails 2.3 with Ruby 1.8.7

+4
source share
1 answer

This is due to how blocks are written to output buffers. See http://railscasts.com/episodes/40-blocks-in-view for more details.

+2
source

All Articles