massive update from upstream, fixes for new rails