Skip to content

Instantly share code, notes, and snippets.

@fdutey
Created January 25, 2009 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdutey/51785 to your computer and use it in GitHub Desktop.
Save fdutey/51785 to your computer and use it in GitHub Desktop.
module ActionView
module Helpers
class InstanceTag
def to_label_tag(text = nil, options = {})
options = options.stringify_keys
name_and_id = options.dup
add_default_name_and_id(name_and_id)
options.delete("index")
options["for"] ||= name_and_id["id"]
if text.blank?
content = method_name.humanize
if object.class.respond_to?(:human_attribute_name)
content = object.class.human_attribute_name(method_name)
end
else
content = text.to_s
end
label_tag(name_and_id["id"], content, options)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment