Last active
August 29, 2015 13:59
-
-
Save rmosolgo/10896335 to your computer and use it in GitHub Desktop.
Append `.json` to URLs for storage operations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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