Simplify code checking whether to enable a locale
This commit is contained in:
@@ -32,10 +32,11 @@ module GlobalizeHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def enable_locale?(resource, locale)
|
def enable_locale?(resource, locale)
|
||||||
# Use `map` instead of `pluck` in order to keep the `params` sent
|
if resource.translations.any?
|
||||||
# by the browser when there's invalid data
|
resource.locales_not_marked_for_destruction.include?(locale)
|
||||||
(resource.translations.blank? && locale == I18n.locale) ||
|
else
|
||||||
resource.translations.reject(&:_destroy).map(&:locale).include?(locale)
|
locale == I18n.locale
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def highlight_class(resource, locale)
|
def highlight_class(resource, locale)
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ module Globalizable
|
|||||||
included do
|
included do
|
||||||
globalize_accessors
|
globalize_accessors
|
||||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||||
|
|
||||||
|
def locales_not_marked_for_destruction
|
||||||
|
translations.reject(&:_destroy).map(&:locale)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class_methods do
|
class_methods do
|
||||||
|
|||||||
Reference in New Issue
Block a user