Module: I18nFields::TranslatableFields::ClassMethods

Defined in:
lib/i18n_fields.rb

Instance Method Summary collapse

Instance Method Details

#field(field_name, *args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/i18n_fields.rb', line 30

def field(field_name, *args)
    
  options = args.extract_options!
  multilingual = options.delete(:translatable) || options.delete(:multilingual)
  args << options

  if multilingual
    @has_translations = true
    translates field_name
    
    self::Translation.class_eval do
      # belongs_to association with translated model is already added by globalize
      
      field field_name, *args
      field :locale
      index :locale
      schema.indexes.keys.each {|k|
        schema.indexes[k].options ||= {}
        schema.indexes[k].options[:name] = "index_#{SecureRandom::uuid}" # avoid index_name too long error
      }
      timestamps
    end
    
  else
    super(field_name, *args)
  end
  
end

#has_translations?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/i18n_fields.rb', line 59

def has_translations?
  !!@has_translations
end