Skip to content

Instantly share code, notes, and snippets.

@nicoolas25
Created November 22, 2013 10:51
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 nicoolas25/7598039 to your computer and use it in GitHub Desktop.
Save nicoolas25/7598039 to your computer and use it in GitHub Desktop.
Add the :required_mark option to the labels. (Rails 4)
class ActionView::Helpers::FormBuilder
alias :original_label :label
# Add the :required_mark option to the label helper that add a mark before the content.
def label(method, content_or_options = nil, options = nil, &block)
if content_or_options && content_or_options.class == Hash
options = content_or_options
else
content = content_or_options
end
# WARNING: This is the way we internationnalize thing in THIS project.
content ||= I18n.t("activerecord.attributes.#{object_name}.#{method}", default: method.to_s.humanize)
content = "* #{content}" if options && options.delete(:required_mark)
original_label(method, content, options || {}, &block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment