Helpful Rails API Snippet
I'm creating a Rails API for an application, and I came acrossed a helpful bit a code that helped make calls, and just the whole API a lot easier to digest.
resources :controller, :defaults => { :format => 'json' }
This allows all routes within the controller to default to JSON. This is great because we are building a Backbone.js driven frontend to talk to the API. This allows all of our URLS to be simple and not have to worry about the .json at the end of the URL.
Written by Aaron Miler
Related protips
1 Response
The problem with that is that it will still try to respond to a different format if provided by the requester.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#