From 3e2cbabc9c20aac76484ea77689280b59cddf346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 3 Jul 2017 12:55:22 +0200 Subject: [PATCH] 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. --- app/helpers/locales_helper.rb | 4 +++- app/views/admin/site_customization/pages/index.html.erb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/helpers/locales_helper.rb b/app/helpers/locales_helper.rb index 717be9e9b..78ab25189 100644 --- a/app/helpers/locales_helper.rb +++ b/app/helpers/locales_helper.rb @@ -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 \ No newline at end of file +end diff --git a/app/views/admin/site_customization/pages/index.html.erb b/app/views/admin/site_customization/pages/index.html.erb index a629a8a8d..dd9cfd3ad 100644 --- a/app/views/admin/site_customization/pages/index.html.erb +++ b/app/views/admin/site_customization/pages/index.html.erb @@ -28,7 +28,7 @@ <%= I18n.l page.created_at, format: :short %> <%= I18n.l page.created_at, format: :short %> <%= t("admin.site_customization.pages.page.status_#{page.status}") %> - <%= name_for_locale(page.locale) rescue nil %> + <%= name_for_locale(page.locale) %> <% if page.status == "published" %>