What are the differences between:
- content_for :header do
%h1 Title
and
= content_for :header do
%h1 Title
What is the right way?
What are the differences between:
- content_for :header do
%h1 Title
and
= content_for :header do
%h1 Title
What is the right way?
That depends on what you want to do.
To render the header right away, do:
= content_for :header do
%h1 Title
To store the content and use it later, do:
- content_for :header do
%h1 Title
And to use it somewhere in your view(s):
= content_for :header
In Rails < 3.2 you needed to use = yield :header
. That is still supported in Rails 3.2 but it doesn't work in helper modules while content_for
does (thanks @drewish).
= yield :header, although not deprecated, has been put to less use. Although Rails 3.2 supports this, but the problem occurs in helper modules. content_for , on the other hand does work well and is a more often used command.