About this user

Anton Kovalyov http://anton.kovalyov.net

« Newer Snippets
Older Snippets »
2 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

Default content-type in Rails

I always forget this.

class ApplicationController < ActionController::Base
  include AuthenticatedSystem
  
  before_filter :set_encoding
  
  private
    def set_encoding
      @headers["Content-type"] ||= "text/html; charset=utf8"
    end
end
« Newer Snippets
Older Snippets »
2 total  XML / RSS feed