Files
grecia/app/models/concerns/globalizable.rb
Senén Rodero Rodríguez a68098eaed Fix sanitization for translatable description attribute
Move method from sanitizable to globalizable concern because
globalize_accessors were overiding sanitizable method and was never
called. Another solution to this could be to load sanitizable
always after globalizable concern.

Old method implementation was not working well with globalize_accessors,
it was returning nil always.
2019-04-17 17:40:56 +02:00

32 lines
864 B
Ruby

module Globalizable
extend ActiveSupport::Concern
included do
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
def locales_not_marked_for_destruction
translations.reject(&:_destroy).map(&:locale)
end
def assign_model_to_translations
translations.each { |translation| translation.globalized_model = self }
end
def description
self.read_attribute(:description).try :html_safe
end
end
class_methods do
def validates_translation(method, options = {})
validates(method, options.merge(if: lambda { |resource| resource.translations.blank? }))
translation_class.instance_eval { validates method, options }
end
def translation_class_delegate(method)
translation_class.instance_eval { delegate method, to: :globalized_model }
end
end
end