From a52cd6bc46701a1d59c85eae9c02cee13363cd39 Mon Sep 17 00:00:00 2001 From: Maciej Litwiniuk Date: Mon, 19 Apr 2021 18:51:47 +0200 Subject: [PATCH] Fixes #162 - Undefined method 'id' for False class error in view partial --- app/controllers/lit/localization_keys_controller.rb | 13 +++++-------- .../localization_keys/_localizations_list.html.erb | 10 +++++++--- lib/lit/cache.rb | 1 + 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/controllers/lit/localization_keys_controller.rb b/app/controllers/lit/localization_keys_controller.rb index a55f9644..5bba6104 100644 --- a/app/controllers/lit/localization_keys_controller.rb +++ b/app/controllers/lit/localization_keys_controller.rb @@ -119,18 +119,15 @@ def grouped_localizations def localization_for(locale, localization_key) @_localization_for ||= {} key = [locale, localization_key] - ret = @_localization_for[key] - if ret == false - nil - elsif ret.nil? + if @_localization_for.key?(key) + @_localization_for[key] + else ret = grouped_localizations[localization_key][locale] unless ret Lit.init.cache.refresh_key("#{locale}.#{localization_key.localization_key}") - ret = localization_key.localizations.where(locale_id: Lit.init.cache.find_locale(locale).id).first + ret = localization_key.localizations.find_by(locale_id: Lit.init.cache.find_locale(locale).id) end - @_localization_for[key] = ret ? ret : false - else - ret + @_localization_for[key] = ret ? ret : nil end end helper_method :localization_for diff --git a/app/views/lit/localization_keys/_localizations_list.html.erb b/app/views/lit/localization_keys/_localizations_list.html.erb index 7e99693b..e1c96f58 100644 --- a/app/views/lit/localization_keys/_localizations_list.html.erb +++ b/app/views/lit/localization_keys/_localizations_list.html.erb @@ -39,9 +39,13 @@ <%- available_locales.each do |locale| %> <%- localization = localization_for(locale, lk) %> - - <%= render partial: 'localization_row', locals: {localization: Lit.init.cache["#{locale}.#{lk.localization_key}"]} %> - + <% if localization %> + + <%= render partial: 'localization_row', locals: {localization: Lit.init.cache["#{locale}.#{lk.localization_key}"]} %> + + <% else %> + missing + <% end %> <%= EmojiFlag.new(locale) %> <%= locale %> diff --git a/lib/lit/cache.rb b/lib/lit/cache.rb index ed1cb9d0..917f2926 100644 --- a/lib/lit/cache.rb +++ b/lib/lit/cache.rb @@ -215,6 +215,7 @@ def localization_keys def find_localization(locale, key_without_locale, value: nil, force_array: false, update_value: false, default_fallback: false) return nil if value.is_a?(Hash) + full_key = "#{locale}.#{key_without_locale}" ActiveRecord::Base.transaction do localization_key = find_localization_key(key_without_locale)