Created
July 18, 2011 16:59
-
-
Save davidjbeveridge/1090061 to your computer and use it in GitHub Desktop.
helper method for helper methods...
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
class ApplicationHelper | |
# Allows you to mark helper methods as safe | |
# eg: helper :my_helper_method | |
class << self | |
private | |
def helper(*meths) | |
meths.each do |meth_name| | |
orig_name = "__helper_#{meth_name.to_s}" | |
alias_method orig_name, meth_name | |
define_method meth_name do |*args| | |
method(orig_name).call(*args).html_safe | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment