Module: TranslatedAttributes::ClassMethods
- Defined in:
- lib/translated_attributes.rb
Instance Method Summary collapse
-
#translated_attributes(*args) ⇒ Object
translated_attributes :title, :description, :table_name=>‘my_translations’.
Instance Method Details
#translated_attributes(*args) ⇒ Object
translated_attributes :title, :description, :table_name=>‘my_translations’
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/translated_attributes.rb', line 6 def translated_attributes(*args) #store options cattr_accessor :translated_attributes_options = (args. || {}).dup [:attribute_column] ||= :translated_attribute self. = .merge(:fields=>args.map(&:to_sym)) #create translations class table_name = [:table_name] || :translations class_name = table_name.to_s.classify associated = [:translatable_name] || :translatable begin klass = Object.const_get(class_name) rescue klass = Class.new(ActiveRecord::Base) Object.const_set(class_name, klass) klass.set_table_name table_name klass.belongs_to associated, :polymorphic => true end #set translations has_many :translations, :as => associated, :dependent => :delete_all, :class_name=>klass.name #include methods include TranslatedAttributes::InstanceMethods end |