Skip to content

Instantly share code, notes, and snippets.

@nicolaracco
Created November 12, 2010 14:05
Show Gist options
  • Save nicolaracco/674120 to your computer and use it in GitHub Desktop.
Save nicolaracco/674120 to your computer and use it in GitHub Desktop.
module Mongoid
module Localizable
class LocalizedValidator < ActiveModel::EachValidator
def validate_each record, attribute, value
if options[:mode] == :only_default
record.errors[:attribute] << (options[:message] || :blank) unless record.send("has_#{attribute}_translation?", I18n.default_locale)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment