Body class for controller in Rails app.

Posted by Vincent on Stack Overflow See other posts from Stack Overflow or by Vincent
Published on 2010-12-29T16:00:13Z Indexed on 2010/12/30 0:54 UTC
Read the original article Hit count: 237

Filed under:
|

Currently I have this in my layout:

<body class="<%= controller.controller_name %>">

I want to add an additional class that will be the same for all actions in any controller where it's set, something like:

class SomeController < ApplicationController

body_class 'page'

...

end


class AnotherController < ApplicationController

body_class 'page'

...

end

Which will result in:

<body class="some page">

<body class="another page">

What would be the easiest way to achieve this? Can I use controller class variables for this?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about helpers