Skip to content

Commit

Permalink
Fixes #162 - Undefined method 'id' for False class error in view partial
Browse files Browse the repository at this point in the history
  • Loading branch information
mlitwiniuk committed Apr 19, 2021
1 parent 850832f commit a52cd6b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
13 changes: 5 additions & 8 deletions app/controllers/lit/localization_keys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions app/views/lit/localization_keys/_localizations_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@
<%- available_locales.each do |locale| %>
<%- localization = localization_for(locale, lk) %>
<tr>
<td class="localization_row" data-id="<%= localization.id%>" data-edit="<%= edit_localization_key_localization_path(lk, localization, format: :js) %>" data-editing=0 data-content="">
<%= render partial: 'localization_row', locals: {localization: Lit.init.cache["#{locale}.#{lk.localization_key}"]} %>
</td>
<% if localization %>
<td class="localization_row" data-id="<%= localization.id%>" data-edit="<%= edit_localization_key_localization_path(lk, localization, format: :js) %>" data-editing=0 data-content="">
<%= render partial: 'localization_row', locals: {localization: Lit.init.cache["#{locale}.#{lk.localization_key}"]} %>
</td>
<% else %>
<td class="localization_row"><em>missing</em></td>
<% end %>
<td class="locale_row text-center">
<%= EmojiFlag.new(locale) %>
<%= locale %>
Expand Down
1 change: 1 addition & 0 deletions lib/lit/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a52cd6b

Please sign in to comment.