config/initializers/autolabel.rb
# add a 'required' CSS class to the field label if the field is required
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
add a 'required' CSS class to the field label if the field is required
rubocop:disable Metrics/CyclomaticComplexity
rubocop:disable Metrics/PerceivedComplexity
add a ' required ' CSS class to the field label if the field is required rubocop : disable Metrics / CyclomaticComplexity rubocop : disable Metrics / PerceivedComplexity
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
    if object.class.respond_to?(:validators_on) &&
      object.class.validators_on(method).map(&:class).include?(ActiveRecord::Validations::PresenceValidator)
      if options.class != Hash
        options = { class: 'required' }
      else
        options[:class] = ((options[:class] || "") + ' required').split(' ').uniq.join(' ')
      end
    end
    orig_label(method, content, options || {}, &block)
  end
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 if object . class . respond_to? ( :validators_on ) && object . class . validators_on ( method ) . map ( & :class ) . include? ( ActiveRecord :: Validations :: PresenceValidator ) if options . class != Hash options = { class : 'required' } else options [ :class ] = ( ( options [ :class ] || "" ) + ' required' ) . split ( ' ' ) . uniq . join ( ' ' ) end end orig_label ( method , content , options || { } , & block ) end
add a 'required' CSS class to the field label if the field is required
rubocop:disable Metrics/CyclomaticComplexity
rubocop:disable Metrics/PerceivedComplexity
add a ' required ' CSS class to the field label if the field is required rubocop : disable Metrics / CyclomaticComplexity rubocop : disable Metrics / PerceivedComplexity
# rubocop:disable Style/MultilineOperationIndentation # rubocop:enable Style/MultilineOperationIndentation
method
<not_specific>
content_or_options
<not_specific>
options
<not_specific>
block
<not_specific>