Created
June 7, 2010 20:16
-
-
Save thorncp/429131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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