Brian Armstrong
Brian Armstrong

Reputation: 19863

Using content_for inline in Rails

I have this in my layout

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

Then in my view this works correctly:

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

But this does not:

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

Does anyone know why?

Btw, this is Rails 2.3 with Ruby 1.8.7

Upvotes: 4

Views: 796

Answers (1)

DGM
DGM

Reputation: 26979

This has to do with the way blocks are captured into output buffers. See http://railscasts.com/episodes/40-blocks-in-view for more info.

Upvotes: 2

Related Questions