Validate both the model and its translations
This way we guarantee there will be at least one translation for a model and we keep compatibility with the rest of the application, which ideally isn't aware of globalize.
This commit is contained in:
@@ -5,4 +5,11 @@ module Globalizable
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user