Created
November 22, 2013 10:51
-
-
Save nicoolas25/7598039 to your computer and use it in GitHub Desktop.
Add the :required_mark option to the labels. (Rails 4)
This file contains hidden or 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 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