Skip to content

Instantly share code, notes, and snippets.

@rmosolgo
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save rmosolgo/10896335 to your computer and use it in GitHub Desktop.

Select an option

Save rmosolgo/10896335 to your computer and use it in GitHub Desktop.
Append `.json` to URLs for storage operations
# Taken from Batman.RailsStorage https://github.com/batmanjs/batman/blob/master/src/extras/batman.rails.coffee#L62
#
# Usage:
# #= require ./json_storage
# class MyApp.Model extends Batman.Model
# @persist Batman.JSONStorage
#
class Batman.JSONStorage extends Batman.RestStorage
# override the default URL functions to add .json:
urlForRecord: -> @_addJsonExtension(super)
urlForCollection: -> @_addJsonExtension(super)
_addJsonExtension: (url) ->
if url.indexOf('?') isnt -1 or url.substr(-5, 5) is '.json'
return url
url + '.json'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment