Skip to content

Instantly share code, notes, and snippets.

@thorncp
Created June 7, 2010 20:16
Show Gist options
  • Save thorncp/429131 to your computer and use it in GitHub Desktop.
Save thorncp/429131 to your computer and use it in GitHub Desktop.
module ApplicationHelper
# Generates a content_for helper using the given symbol as
# the method name.
#
# Example: this code generates a method called 'head' that
# will be available in all views.
# content_for_helper :head
def self.content_for_helper(sym)
define_method sym do |content|
content_for sym, content
yield(content) if block_given?
end
end
# Used to dump html into the <head> tag of the current view.
# Useful for page specific js and css
content_for_helper :head
# Used specifically to specify the title of the current view.
content_for_helper :title do |content|
content_tag(:h2, content)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment