use I18n.with_locale wherever possible, since it catches errors properly
In particular, pet#load was handling locale-switching itself, but wasn't switching back to original locale on error. We could've used a rescue block, but, when I18n.with_locale is so cool, may as well use it fully.
This commit is contained in:
parent
85d52c23c3
commit
573e8a6459
2 changed files with 41 additions and 45 deletions
|
@ -43,10 +43,9 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def canonical_path(resource)
|
||||
original_locale = I18n.locale
|
||||
I18n.locale = I18n.default_locale
|
||||
I18n.with_locale(I18n.default_locale) do
|
||||
content_for :meta, tag(:link, :rel => 'canonical', :href => url_for(resource))
|
||||
I18n.locale = original_locale
|
||||
end
|
||||
end
|
||||
|
||||
def contact_email
|
||||
|
|
|
@ -20,9 +20,7 @@ class Pet < ActiveRecord::Base
|
|||
options[:item_scope] ||= Item.scoped
|
||||
options[:locale] ||= I18n.default_locale
|
||||
|
||||
original_locale = I18n.locale
|
||||
I18n.locale = options[:locale]
|
||||
|
||||
I18n.with_locale(options[:locale]) do
|
||||
require 'ostruct'
|
||||
begin
|
||||
neopets_language_code = I18n.neopets_language_code_for(options[:locale])
|
||||
|
@ -60,8 +58,7 @@ class Pet < ActiveRecord::Base
|
|||
contents.object_info_registry, contents.object_asset_registry,
|
||||
options[:item_scope])
|
||||
end
|
||||
|
||||
I18n.locale = original_locale
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue