pseudomuto/routesjs-rails — pull request #8 by pseudomuto (2014-09-27 23:45:43+00:00)
Title: Support for formats

@qq99, @kevcenteno hoping to get a couple of opinions here. What do you guys think?

# The Problem

Not all routes should just use the extension-less version of the route. There are times when you want to use `.json` or `.html` or even `.my_custom_thing` (hopefully never the last one :smile:).

Currently routes are always drawn without these formats (to use the railsy) term. This means you'd have this kind of ugliness in your JS:

```
var url = Routes.adminPath() + ".json";
...
...
```

In a word...ew.

# The Solution

I've added the ability to pass `format: ""` as part of the route params object. This way you can do:

`Routes.userPath({ id: 1, format: "json" }) // returns /users/1.json`

You can also specify a global default format in the initializer (generated by running `rails g routes_js:install`. When a default is specified, the format property in the call takes precedence. You can see this in the _test/javascripts/routesjs-rails_spec.js_ file.