Rails 4.0 upgrade

Another batch of fixes. PR Carlos's Pull Request first.