Locales helper improvement

Added a rescue block in `name_for_locale()` to ensure the application doesn't crash in case it receives an invalid locale.
This commit is contained in:
María Checa
2017-07-03 12:55:22 +02:00
parent da2b55942a
commit 3e2cbabc9c
2 changed files with 4 additions and 2 deletions

View File

@@ -3,6 +3,8 @@ module LocalesHelper
def name_for_locale(locale)
default = I18n.t("locale", locale: locale)
I18n.backend.translate(locale, "i18n.language.name", default: default)
rescue
nil
end
end

View File

@@ -28,7 +28,7 @@
<td><%= I18n.l page.created_at, format: :short %></td>
<td><%= I18n.l page.created_at, format: :short %></td>
<td><%= t("admin.site_customization.pages.page.status_#{page.status}") %></td>
<td><%= name_for_locale(page.locale) rescue nil %></td>
<td><%= name_for_locale(page.locale) %></td>
<td class="small">
<span class="icon-eye"></span>
<% if page.status == "published" %>