Rails 4 support and make sure to return JSON object.

Thanks to Martin Lang (@MJLang) for the Rails 4 changes.