Last Updated: January 28, 2021
·
1.137K
· aaronmiler

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.

1 Response
Add your 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 ·