Sha256: b5eebfb3145b0808dfcc55d4efc17a756e4f5e6beecbe0fbcde740ac5b027fca
Contents?: true
Size: 986 Bytes
Versions: 1
Compression:
Stored size: 986 Bytes
Contents
module SpreeMobility::CoreExt::Spree::OptionValueDecorator module TranslationMethods def name_uniqueness_validation return unless name.present? return unless translated_model check_scope = ::Spree::OptionValue. where.not(id: translated_model.id). where(option_type_id: translated_model.option_type_id). joins(:translations). where(spree_option_value_translations: { locale: locale }). where('LOWER(spree_option_value_translations.name) = LOWER(?)', name) if check_scope.exists? errors.add(:name, :taken, value: name) end end end def self.prepended(base) base.include SpreeMobility::Translatable SpreeMobility.translates_for base, :name, :presentation base.translation_class.class_eval do include TranslationMethods validate :name_uniqueness_validation validates :name, presence: true validates :presentation, presence: true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spree_mobility-1.0.0 | lib/spree_mobility/core_ext/spree/option_value_decorator.rb |