lib/will_translate/class_methods.rb
# Adds localisable fields to an ActiveRecord object. This will automatically create getters and setters for these
# fields.
#
# === Parameters
#
# [fields]  an array containing field names (as strings or symbols) that you wish to be localised.
Adds localisable fields to an ActiveRecord object. This will automatically create getters and setters for these
fields.

Parameters

[fields]  an array containing field names (as strings or symbols) that you wish to be localised.
Adds localisable fields to an ActiveRecord object . This will automatically create getters and setters for these fields . Parameters [ fields ] an array containing field names ( as strings or symbols ) that you wish to be localised .
def will_translate( *fields )
      include InstanceMethods
      has_many :wt_translations, :as => :translateable, :dependent => :destroy
      after_initialize  :load_translations
      after_save        :save_translations
      fields.each do |field|
        define_method "#{field}" do |args = {}|          
          get_translated_content field.to_sym, args
        end
        define_method "#{field}?" do
          !send("#{field}").blank?
        end
        define_method "#{field}=" do |args = {}|
          set_translated_content field.to_sym, args
        end
        self.localised_fields = fields
      end      
    end
def will_translate ( * fields ) include InstanceMethods has_many :wt_translations , :as => :translateable , :dependent => :destroy after_initialize :load_translations after_save :save_translations fields . each do | field | define_method "#{field}" do | args = { } | get_translated_content field . to_sym , args end define_method "#{field}?" do ! send ( "#{field}" ) . blank? end define_method "#{field}=" do | args = { } | set_translated_content field . to_sym , args end self . localised_fields = fields end end
Adds localisable fields to an ActiveRecord object.
Adds localisable fields to an ActiveRecord object .
# add new relations # hooks # define getters and setters for each field # getter # setter
fields
<not_specific>