Lucid Lynx a fresh install with ruby, rails, passenger etc

A fresh install for my laptop, with some Desktop tools ans all the rails/ruby stuff i need. I tried using rvm for all gems, but since executables are not available it kind of sucks for things like passenger, where youd have to change the ruby path all the time, a real showstopper imo.

  1. Replace radiance theme with clearlock
  2. copy important dotfiles + firefox history/forms/… database from .mozilla
  3. install dotfiles
  4. Multi-clipboard: sudo apt-get install glipper (add to panel)
  5. install Skype
  6. Application laucher: sudo apt-get install gnome-do + enable skype plugin
  7. Ruby enterprise
  8. Java: sudo apt-get install sun-java6-jre
  9. Rubymine + add Rubymine Desktop icon + choose “meta is mapped to left win” in advanced keyboard layout options
  10. Mysql: sudo apt-get install mysql-server mysql-client libmysql-ruby
  11. Apache:  sudo apt-get install build-essential apache2 apache2-mpm-prefork apache2-prefork-dev
  12. sudo a2enmod rewrite
  13. Passenger
  14. SSL for apache/passenger
  15. gem sources -a http://gems.github.com
  16. gems…
  17. Git: sudo apt-get install git-core git-svn
  18. install redis
  19. sudo apt-get install memcached + add memcached -d to startup
  20. Arial/Verdana etc fonts:   sudo apt-get install msttcorefonts
  21. VirtualBox

Empty session id leads to shared session + Fix

We recently encountered some users that had an empty sessionid and therefore where logged in as other users, to fix this (the reason why the ids where empty is still unknown….) we now forbid blank session ids.

# users with blank session id get logged in as other users / share session 
#-> forbid empty session ids
# TEST: set _session_id cookie to "" it should be removed/replaced
class ActionController::Session::AbstractStore
  def load_session_with_blank_id_protection(*args)
    id, data = load_session_without_blank_id_protection(*args)
    return [nil, {}] if id.blank?
    [id, data]
  end
  alias_method_chain :load_session, :blank_id_protection
end

ActiveRecord without default scope

This is a pretty hacky implementation of the feature we needed:
remove the default scope for some queries (e.g. update deleted records)

Code:

class ActiveRecord::Base
  def self.without_default_scope(&block)
    scope = scoped({})
    defaults = scope.current_scoped_methods_when_defined

    old = defaults[:find][:conditions]
    defaults[:find][:conditions] = {}

    begin
      yield(scope)
    ensure
      defaults[:find][:conditions] = old
    end
  end
end

Usage

MYModel.without_default_scope{|s| s.update_all(:deleted_at => nil)}

There is an less hacky alternative, but it did not work for us (AR 2.3.2)

Joined environment file for production and staging

Often production and staging share much, so why not use a common file for that…

#config/environments/production.rb and config/environments/staging.rb
eval(File.read("#{File.dirname(__FILE__)}/production_like.rb"))
...environment specific code ...

#config/environments/production_like.rb
config.cache_classes = true
...

the File.read/eval is rather hacky, but works nevertheless 😉