improve compatibility with rails 4; add compatibility with rails 3.2