Support Rails 4.2.0 with AMS 0.9

This patch is the same fixes as #655 and #663 for 0-9-stable branch.