Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

ActiveRecord attribute calls interception (See related posts)

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

You need to create an account or log in to post comments to this site.


Related Posts