Working for rails 3.1+