Skip to content

Instantly share code, notes, and snippets.

@Lytol
Created July 5, 2011 21:14
Show Gist options
  • Save Lytol/1065962 to your computer and use it in GitHub Desktop.
Save Lytol/1065962 to your computer and use it in GitHub Desktop.
Body tag helper that sets class and id based on controller/action
def body_tag(&blk)
controller_name = controller.class.to_s.underscore.gsub(/_controller$/, '').gsub(/\//,'_')
action_name = controller.action_name.underscore.gsub(/_/,'-')
content_tag(:body, :id => "#{controller_name}-#{action_name}", :class => controller_name, &blk)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment