After using Drupal's template.php file to preprocess html and add unique classes to various html elements, I because very dependent on page specific css classes. While building a Ruby on Rails app, I thought it would be nice to at least add in a page-specific body class. Here's a quick snippet you can use:<% page = request.request_uri.gsub(/^(\/)?/, '') page = page.gsub(/\//, '-') %> ">
- Grab the current url (after the domain)
- Strip the leading slash
- Replace all forward slashes with dashes
I highly recommend this post on Rails for PHP developers. As a PHP developer, I found that it really helped to smooth out the Ruby learning curve.