Retrieve internationalized label text without label tag wrapper

The method FormBuilder#label( see docs ) returns a tag <label>for this attribute. If the user does not provide text for the tag, the i18n library is used for search. Inspection Procedure:

  • helpers.label.object.method
  • object.class.human_attribute_name(method_name)
  • method_name.humanize

Is there an API method anywhere that does a similar search but DOES NOT complete the output in the tag <label>? If not, then the best way to remove the tag <label>from the tag returned FormBuilder#labelis without removing any other html tags that may contain the internationalized string.

+5
source share
2 answers

, . ...

label(attribute,text).gsub(/^<label(.*?)>/,'').gsub(/<\/label>$/,'')

0

, Class.human_attribute_name(attribute), ex:

Person.human_attribute_name("first_name") # => "First name"
# you can also use :first_name

0

All Articles