我正在做一个多语言项目。我正在使用 I18n gem 进行本地化。在某些时候,我想传递一个空值,如下所示:
current_locale("")
current_locale()
函数在哪里
def current_locale(locale)
if locale.empty?
translation = find_translation(locale)
else
translation = find_translation( I18n.locale ) || find_translation( I18n.default_locale ) || translations.first
end
translation.locale
end
但是当current_locale()
调用该函数时,它给了我以下错误:
undefined method `locale' for nil:NilClass
有谁知道如何解决这个错误?
谢谢