ClassyBody

Adds a bit of class to your body.

By default it adds the controller & the action name and the current id.

Optional: mobile and anything you supply.

Installation

Add this line to your application's Gemfile:

gem 'classy_body'

And then execute:

$ bundle install

In your applications layout (eg application.html.erb) add this to your body

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

Usage

By default it will create for eg. http://example.com/users/show/andreasklinger

<body class="users show andreasklinger">

You can also add custom classes via the view if needed

eg. in users#show

<% content_for :body_class, %Q(narrow-layout active-user) %>

will create when viewed via mobile browser

<body class="users show andreasklinger narrow-layout active-user mobile">

Notes

This gem is heavily based on this gist by @darph After building this gem i found flutie which offers the same functionality.

Contributing

  1. Fork it ( http://github.com//classy_body/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request