A rails responder for json.
Add this line to your application's Gemfile:
gem 'json_responder', git: 'git@github.com:zacharywelch/json_responder.git'
And then execute:
$ bundle
Add Responders::JsonResponder
to your responder chain:
class ApplicationResponder < ActionController::Responder
include Responders::JsonResponder
end
class MyController < ApplicationController
self.responder = ApplicationResponder
end
JsonResponder changes a few behaviors on responders:
- Put returns the resource with a status code of 200 instead of 204 No Content
- Resource errors are returned using the default json array instead of a hash with an errors key
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Add tests for your feature.
- Add your feature.
- Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request