Skip to content

Instantly share code, notes, and snippets.

@moutten
Forked from timnovinger/bodyid.rb
Created October 15, 2009 21:18
Show Gist options
  • Select an option

  • Save moutten/211291 to your computer and use it in GitHub Desktop.

Select an option

Save moutten/211291 to your computer and use it in GitHub Desktop.
###############################################
# place in /app/helpers/application_helper.rb #
###############################################
def bodytag_id
a = controller.controller_name.underscore
b = controller.action_name.underscore
"#{a}-#{b}".gsub(/_/, '-')
end
def bodytag_class
controller.controller_name.underscore.gsub(/_/, '-')
end
#################
# place in html #
#################
<body id="<%= bodytag_id %>" class="<%= bodytag_class %>">
http://www.fivesevensix.com/posts/2005/04/15/automatic-body-tag-id-with-rails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment