Module: HasManyTranslations::Creation::ClassMethods
- Defined in:
- lib/has_many_translations/creation.rb
Overview
Class methods added to ActiveRecord::Base to facilitate the creation of new translations.
Instance Method Summary collapse
-
#prepare_translated_options_with_creation(options) ⇒ Object
Overrides the basal
prepare_has_translations_options
method defined in HasManyTranslations::Options to extract the:only
and:except
options intohas_many_translations_options
.
Instance Method Details
#prepare_translated_options_with_creation(options) ⇒ Object
Overrides the basal prepare_has_translations_options
method defined in HasManyTranslations::Options to extract the :only
and :except
options into has_many_translations_options
.
26 27 28 29 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 |
# File 'lib/has_many_translations/creation.rb', line 26 def () self.columns.map{|c|c.type == :string || c.type == :text ? c.name : nil}.compact.each{|name| #alias_method "#{name}_before_translation", name.to_sym #unless try(name) define_method name, lambda { |*args| # unless self.translations.blank? || self.translations.first.origin_locale_code == self.hmt_locale || read_attribute(name.to_sym).nil? trans = self.translations.first(:conditions => {:locale_code => self.hmt_locale, :attribute => name}) val = trans.nil? ? read_attribute(name.to_sym) : trans.value #self.hmt_locale else #self.id read_attribute(name.to_sym) #try(name) end #HasManyTranslations.fetch(args.first || self.class.locale || I18n.locale, name) } alias_method "#{name}_before_type_cast", name } result = () self.[:only] = Array(.delete(:only)).map(&:to_s).uniq if [:only] self.[:except] = Array(.delete(:except)).map(&:to_s).uniq if [:except] #self.has_many_translations_options[:locales] = Array(options.delete(:locales)).map(&:to_s).uniq if options[:locales] result end |