This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'active_support' | |
# Include this module to define additional helpers | |
module MyAccessors | |
extend ActiveSupport::Concern | |
module ClassMethods | |
# This helper creates accessors | |
def create_my_accessors *names |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Model | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
include Mongoid::Localizable | |
localized_field :name | |
validates_default_locale :name | |
end | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder