Support Rails 4.2.0

This patch is the same fixes as #655 and #663 .