About this user

Anton Kovalyov http://anton.kovalyov.net

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

ActiveRecord attribute calls interception

I need to intercept attribute calls and add some additional info to them.

class ActiveRecord::Base
  def self.multilingual_field(fieldname)
    module_eval <<-end_eval
      def #{fieldname}
        send("#{fieldname}_\#{Locale.language.short_name}")
      end

      def #{fieldname}=(value)
        send("#{fieldname}_\#{Locale.language.short_name}=",value)
      end
    end_eval
  end
end
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed