grosser / gettext_i18n_rails

Rails: FastGettext, I18n integration -- simple, threadsafe and fast!
MIT License
268 stars 91 forks source link

raise raise undefined method `split' for nil:NilClass when validating foreign_keys #172

Closed neohunter closed 7 years ago

neohunter commented 7 years ago

ActiveModel::Translation has

def human_attribute_name(attribute, *args)
      s_(gettext_translation_for_attribute_name(attribute))
end

def gettext_translation_for_attribute_name(attribute)
      attribute = attribute.to_s
      if attribute.ends_with?('_id')
        humanize_class_name(attribute)
      else
        "#{inheritance_tree_root(self)}|#{attribute.split('.').map! {|a| a.humanize }.join('|')}"
      end
    end

the first method calls the 2nd passing an attribute like chat_id.

As it ends with _id it executes the first if,

the return of humanize_class_name(attribute) is nil.

That cause the undefined method split for nil classes when using with rails validate_uniqueness_of

neohunter commented 7 years ago

Duh, sorry, was a dumb monkey patching on the project I was working on