transit-rails
Use transit format in your Rails application, with minimal friction.
Works wherever transit-ruby
does.
Installation
Add this line to your application's Gemfile:
gem 'transit-rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install transit-rails
Usage
In a Rails controller:
def index
@posts = Post.all
respond_to do |format|
format.html
format.transit { render transit: @posts }
end
end
The renderer can take a verbose
flag, which when true will output
transit in the json-verbose
format.
def index
@posts = Post.all
render transit: @posts, verbose: true
end
You can supply any custom handlers using the handlers
option.
def index
@person = Person.new
render transit: @person, handlers: { Person => PersonHandler.new }
end
Read more about custom handlers on the transit-ruby README.
Contributing
- Fork it ( https://github.com/jgdavey/transit-rails/fork )
- Create your feature branch (
git checkout -b my-new-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