Skip to content

Instantly share code, notes, and snippets.

@davidjbeveridge
Created July 18, 2011 16:59
Show Gist options
  • Save davidjbeveridge/1090061 to your computer and use it in GitHub Desktop.
Save davidjbeveridge/1090061 to your computer and use it in GitHub Desktop.
helper method for helper methods...
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