Allow create translations without length validation
We have changed validate_translation method on Globalize concern.
The objective is skip length validations when locale is distinct to
default_locale.
First we force apply :length validations when locale is equal to
default_locale. After we reject :length from options and apply rest
of validation options only when we have more than 1 options.
Ej: options = { length: "maximum: 10" }
When reject :length option in this example, options is equal to a
empty hash and we cant execute validations.
This commit is contained in:
@@ -35,8 +35,20 @@ module Globalizable
|
|||||||
class_methods do
|
class_methods do
|
||||||
def validates_translation(method, options = {})
|
def validates_translation(method, options = {})
|
||||||
validates(method, options.merge(if: lambda { |resource| resource.translations.blank? }))
|
validates(method, options.merge(if: lambda { |resource| resource.translations.blank? }))
|
||||||
|
if options.include?(:length)
|
||||||
|
lenght_validate = { length: options[:length] }
|
||||||
|
translation_class.instance_eval do
|
||||||
|
validates method, lenght_validate.merge(if: lambda { |translation| translation.locale == I18n.default_locale })
|
||||||
|
end
|
||||||
|
if options.count > 1
|
||||||
|
translation_class.instance_eval do
|
||||||
|
validates method, options.reject { |key| key == :length }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
translation_class.instance_eval { validates method, options }
|
translation_class.instance_eval { validates method, options }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def translation_class_delegate(method)
|
def translation_class_delegate(method)
|
||||||
translation_class.instance_eval { delegate method, to: :globalized_model }
|
translation_class.instance_eval { delegate method, to: :globalized_model }
|
||||||
|
|||||||
Reference in New Issue
Block a user