user1919937 user1919937 - 4 months ago 57
Ruby Question

Add Class To Body Using ERB In A View - Rails

I've watched this screencast to add a page title when in a view, is there a way I can do the same but add a class the body tag?

Answer

Not sure what you mean, you can do it the same way:

In a view:

<% content_for :body_class, "my_class" %>

In a layout file:

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