Skip to content

Instantly share code, notes, and snippets.

@timnovinger
Created October 14, 2009 13:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save timnovinger/210079 to your computer and use it in GitHub Desktop.
Save timnovinger/210079 to your computer and use it in GitHub Desktop.
Automatic Body ID in Rails
###############################################
# place in /app/helpers/application_helper.rb #
###############################################
def bodytag_id
a = controller.class.to_s.underscore.gsub(/_controller$/, '')
b = controller.action_name.underscore
"#{a}-#{b}".gsub(/_/, '-')
end
#################
# place in html #
#################
<body id="<%= bodytag_id %>" class="standard">
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