Add a unique body class in Ruby on Rails template

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(/\//, '-') %> ">

This will:

  1. Grab the current url (after the domain)
  2. Strip the leading slash
  3. 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.

I am interested in becoming your subscriber, so please keep me updated. I find the thoughts and opinions of this blogger, very inspiring and actually worth following. Nice work.
<a href="">ez lease rentals review</a>

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.