updated for Rails 4, working for MySQL and PostgreSQL