I have the following little problem.
In layout I yield to content_for to set up some classes on my body tag:
<body class="<%= yield(:body_classes) %>
They I would like to call content_for
<%= content_for(:body_classes, "one") %>
So far so good. I use content_for for the second time:
<%= content_for(:body_classes, "two") %>
In my HTML I get the following:
<body class="onetwo">
Is there an elegant way to separate those two classes by space? I can think of couple of hacky solution, but nothing feels right…
Many Thanks!
I don’t think
content_foris a good fit in this case. However, you can solve the problem elegantly with a couple of helper methods (extracted from one of my Rails projects):Usage in templates:
In the layout, determine if a certain class is set:
And finally…
You can further customize these to better suit your needs.